-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt_array_test.go
122 lines (85 loc) · 2.36 KB
/
fmt_array_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package fmt_test
import (
"github.com/MontFerret/fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestArrayFormatter(t *testing.T) {
Convey("Array", t, func() {
Convey("Empty", func() {
f := fmt.New()
out := f.MustFormat(`
LET a = [ ]
RETURN a
`)
So(out, ShouldEqual, `LET a = []
RETURN a`)
})
Convey("Not empty", func() {
f := fmt.New()
out := f.MustFormat(`
LET a = [ 1, 2.5, "foo",
NONE ]
RETURN a
`)
So(out, ShouldEqual, `LET a = [1, 2.5, "foo", NONE]
RETURN a`)
})
Convey("Nested", func() {
f := fmt.New()
out := f.MustFormat(`
LET a = [ 1, 2.5, "foo",
NONE , [ 1 , TRUE, FALSE,
"asda"
] ]
RETURN a
`)
So(out, ShouldEqual, `LET a = [1, 2.5, "foo", NONE, [1, TRUE, FALSE, "asda"]]
RETURN a`)
})
Convey("Too long", func() {
f := fmt.New(fmt.WithPrintWidth(40))
out := f.MustFormat(`
LET a = ["Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"]
RETURN a
`)
So(out, ShouldEqual, `LET a = [
"Lorem ipsum dolor sit amet",
"Lorem ipsum dolor sit amet",
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
]
RETURN a`)
})
Convey("Too long nested", func() {
f := fmt.New(fmt.WithPrintWidth(40))
out := f.MustFormat(`
LET a = ["Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet", ["sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat", ["foo","bar"]]]
RETURN a
`)
So(out, ShouldEqual, `LET a = [
"Lorem ipsum dolor sit amet",
"Lorem ipsum dolor sit amet",
[
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
"quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat",
["foo", "bar"]
]
]
RETURN a`)
})
Convey("Of objects", func() {
f := fmt.New(fmt.WithPrintWidth(40))
out := f.MustFormat(`
LET a = [{ a: 1, b: { c: "d" } }, { a: 1, b: { c: "d" } }, { a: 1, b: { c: "d" } }, { a: 1, b: { c: "d" } }]
RETURN a
`)
So(out, ShouldEqual, `LET a = [
{ a: 1, b: { c: "d" } },
{ a: 1, b: { c: "d" } },
{ a: 1, b: { c: "d" } },
{ a: 1, b: { c: "d" } }
]
RETURN a`)
})
})
}