Skip to content

Commit

Permalink
Add tests for skipping arrays & objects
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Oct 4, 2022
1 parent 4f2c49b commit 5581a54
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions flatten_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,46 @@ func TestFJStrings(t *testing.T) {
)
}

func TestFJSkippingBlocks(t *testing.T) {
j := `{
"skipped_objects_with_objects": {
"num": 1,
"str": "hello world",
"arr": [1, "yo", { "k": "val", "arr": [1, 2, "name"] }],
"obj": {
"another_obj": {
"name": "yo",
"patterns": [{ "a": 1 }, { "b": [1, 2, 3] }, "d"]
}
}
},
"skipped_array_of_primitives": [1, 324, 534, "string"],
"skipped_array_of_arrays": [[0, 1], ["lat", "lng"], [{ "name": "quamina" }, { "description": "patterns matching" }]],
"requested_object": {
"another_num": 1,
"another_str": "hello world",
"another_arr": [1, "yo", { "k": "val", "arr": [1, 2, "name"] }],
"another_obj": {
"key": "value"
}
},
}`
matcher := fakeMatcher("requested_object", "another_obj", "key")

f := newJSONFlattener()
list, err := f.Flatten([]byte(j), matcher)
if err != nil {
t.Error("E: " + err.Error())
}

expectToHavePaths(t,
list,
[]string{"requested_object\nanother_obj\nkey"},
[]string{`"value"`},
)
}


func TestFJ10Lines(t *testing.T) {
geo := fakeMatcher("type", "geometry")
testTrackerSelection(t, newJSONFlattener(), geo, "L0", "testdata/cl-sample-0", []string{"type", "geometry\ntype"}, []string{`"Feature"`, `"Polygon"`})
Expand Down

0 comments on commit 5581a54

Please sign in to comment.