Skip to content

Commit bf87297

Browse files
leslie-qiwanqd
authored andcommitted
Add test case in which keys start with upper/lower case
Signed-off-by: Leslie Qi Wang <[email protected]>
1 parent 89ec4af commit bf87297

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

flat_test.go

+65-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestFlatten(t *testing.T) {
1212
options *Options
1313
want map[string]interface{}
1414
}{
15-
// test with different primitives
15+
// test with different primitives and upper/lower case
1616
// String: 'world',
1717
// Number: 1234.99,
1818
// Boolean: true,
@@ -22,6 +22,11 @@ func TestFlatten(t *testing.T) {
2222
nil,
2323
map[string]interface{}{"hello": "world"},
2424
},
25+
{
26+
`{"Hello": "world"}`,
27+
nil,
28+
map[string]interface{}{"Hello": "world"},
29+
},
2530
{
2631
`{"hello": 1234.99}`,
2732
nil,
@@ -48,6 +53,21 @@ func TestFlatten(t *testing.T) {
4853
nil,
4954
map[string]interface{}{"hello.world": "good morning"},
5055
},
56+
{
57+
`{"Hello":{"world":"good morning"}}`,
58+
nil,
59+
map[string]interface{}{"Hello.world": "good morning"},
60+
},
61+
{
62+
`{"hello":{"World":"good morning"}}`,
63+
nil,
64+
map[string]interface{}{"hello.World": "good morning"},
65+
},
66+
{
67+
`{"Hello":{"World":"good morning"}}`,
68+
nil,
69+
map[string]interface{}{"Hello.World": "good morning"},
70+
},
5171
{
5272
`{"hello":{"world":1234.99}}`,
5373
nil,
@@ -185,6 +205,12 @@ func TestUnflatten(t *testing.T) {
185205
nil,
186206
map[string]interface{}{"hello": "world"},
187207
},
208+
// Key starts with upper case
209+
{
210+
map[string]interface{}{"Hello": "world"},
211+
nil,
212+
map[string]interface{}{"Hello": "world"},
213+
},
188214
{
189215
map[string]interface{}{"hello": 1234.56},
190216
nil,
@@ -233,6 +259,44 @@ func TestUnflatten(t *testing.T) {
233259
},
234260
},
235261
},
262+
// multiple keys - key starts with upper case
263+
{
264+
map[string]interface{}{
265+
"Hello.lorem.ipsum": "L1 upper",
266+
"hello.lorem.ipsum": "L1 lower",
267+
"hello.Lorem.dolor": "L2 upper",
268+
"hello.lorem.dolor": "L2 lower",
269+
"world.lorem.Ipsum": "L3 upper",
270+
"world.lorem.ipsum": "L3 lower",
271+
"world.lorem.dolor": "sit",
272+
"world": map[string]interface{}{
273+
"greet": "hello",
274+
"From": "alice",
275+
},
276+
},
277+
nil,
278+
map[string]interface{}{
279+
"hello": map[string]interface{}{
280+
"lorem": map[string]interface{}{
281+
"ipsum": "L1 lower",
282+
"dolor": "L2 lower",
283+
},
284+
"Lorem": map[string]interface{}{"dolor": "L2 upper"},
285+
},
286+
"Hello": map[string]interface{}{
287+
"lorem": map[string]interface{}{"ipsum": "L1 upper"},
288+
},
289+
"world": map[string]interface{}{
290+
"greet": "hello",
291+
"From": "alice",
292+
"lorem": map[string]interface{}{
293+
"ipsum": "L3 lower",
294+
"Ipsum": "L3 upper",
295+
"dolor": "sit",
296+
},
297+
},
298+
},
299+
},
236300
// nested objects do not clobber each other
237301
{
238302
map[string]interface{}{

0 commit comments

Comments
 (0)