Skip to content

Commit 5581a54

Browse files
committed
Add tests for skipping arrays & objects
1 parent 4f2c49b commit 5581a54

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

flatten_json_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,46 @@ func TestFJStrings(t *testing.T) {
5656
)
5757
}
5858

59+
func TestFJSkippingBlocks(t *testing.T) {
60+
j := `{
61+
"skipped_objects_with_objects": {
62+
"num": 1,
63+
"str": "hello world",
64+
"arr": [1, "yo", { "k": "val", "arr": [1, 2, "name"] }],
65+
"obj": {
66+
"another_obj": {
67+
"name": "yo",
68+
"patterns": [{ "a": 1 }, { "b": [1, 2, 3] }, "d"]
69+
}
70+
}
71+
},
72+
"skipped_array_of_primitives": [1, 324, 534, "string"],
73+
"skipped_array_of_arrays": [[0, 1], ["lat", "lng"], [{ "name": "quamina" }, { "description": "patterns matching" }]],
74+
"requested_object": {
75+
"another_num": 1,
76+
"another_str": "hello world",
77+
"another_arr": [1, "yo", { "k": "val", "arr": [1, 2, "name"] }],
78+
"another_obj": {
79+
"key": "value"
80+
}
81+
},
82+
}`
83+
matcher := fakeMatcher("requested_object", "another_obj", "key")
84+
85+
f := newJSONFlattener()
86+
list, err := f.Flatten([]byte(j), matcher)
87+
if err != nil {
88+
t.Error("E: " + err.Error())
89+
}
90+
91+
expectToHavePaths(t,
92+
list,
93+
[]string{"requested_object\nanother_obj\nkey"},
94+
[]string{`"value"`},
95+
)
96+
}
97+
98+
5999
func TestFJ10Lines(t *testing.T) {
60100
geo := fakeMatcher("type", "geometry")
61101
testTrackerSelection(t, newJSONFlattener(), geo, "L0", "testdata/cl-sample-0", []string{"type", "geometry\ntype"}, []string{`"Feature"`, `"Polygon"`})

0 commit comments

Comments
 (0)