-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflattener_test.go
77 lines (74 loc) · 1.43 KB
/
flattener_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
package flatjson
import (
"strconv"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWriteValues(t *testing.T) {
for i, tc := range []struct {
prefix string
json string
expected string
}{
{
json: `{}`,
expected: "root = {};\n",
},
{
json: `[]`,
expected: "root = [];\n",
},
{
json: `0`,
expected: "root = 0;\n",
},
{
json: `""`,
expected: "root = \"\";\n",
},
{
json: `true`,
expected: "root = true;\n",
},
{
json: `false`,
expected: "root = false;\n",
},
{
json: `null`,
expected: "root = null;\n",
},
{
json: `[1,2,3]`,
expected: "root = [];\nroot[0] = 1;\nroot[1] = 2;\nroot[2] = 3;\n",
},
{
json: `{"a":{"b":"c"}}`,
expected: "root = {};\nroot.a = {};\nroot.a.b = \"c\";\n",
},
{
json: `{"a.b":"c"}`,
expected: "root = {};\nroot[\"a.b\"] = \"c\";\n",
},
{
json: `{"false":false}`,
expected: "root = {};\nroot[\"false\"] = false;\n",
},
{
json: `{"null":false}`,
expected: "root = {};\nroot[\"null\"] = false;\n",
},
{
json: `{"true":false}`,
expected: "root = {};\nroot[\"true\"] = false;\n",
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
sb := &strings.Builder{}
require.NoError(t, NewFlattener(sb).WriteValues([]byte(tc.json)))
assert.Equal(t, tc.expected, sb.String())
})
}
}