diff options
author | NeonXP <i@neonxp.dev> | 2022-12-27 02:37:02 +0300 |
---|---|---|
committer | NeonXP <i@neonxp.dev> | 2022-12-27 02:40:03 +0300 |
commit | 76a7f461ebbde70ea0e3d4f9b79c08139acaee7c (patch) | |
tree | 5e6dcb05f00be5109b3465ef16a6e9169a27497e /query_test.go | |
parent | 6f1d1df79f161cfc695f74d271d689ba72c44d09 (diff) |
Completely rewritedv0.1.0
Diffstat (limited to 'query_test.go')
-rw-r--r-- | query_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/query_test.go b/query_test.go new file mode 100644 index 0000000..44383de --- /dev/null +++ b/query_test.go @@ -0,0 +1,65 @@ +package json_test + +import ( + "reflect" + "testing" + + "go.neonxp.dev/json" + "go.neonxp.dev/json/std" +) + +func TestMustQuery(t *testing.T) { + jsonString := `{ + "string key": "string value", + "number key": 123.321, + "bool key": true, + "object": { + "one": "two", + "object 2": { + "three": "four" + } + }, + "array": [ + "one", + 2, + true, + null, + { + "five": "six" + } + ] + }` + type args struct { + parent json.Node + path []string + } + tests := []struct { + name string + args args + want json.Node + }{ + { + name: "find in object", + args: args{ + parent: json.New(std.Factory).MustUnmarshal(jsonString), + path: []string{"object", "object 2", "three"}, + }, + want: &std.StringNode{Value: "four"}, + }, + { + name: "find in array", + args: args{ + parent: json.New(std.Factory).MustUnmarshal(jsonString), + path: []string{"array", "[4]", "five"}, + }, + want: &std.StringNode{Value: "six"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := json.MustQuery(tt.args.parent, tt.args.path); !reflect.DeepEqual(got, tt.want) { + t.Errorf("MustQuery() = %v, want %v", got, tt.want) + } + }) + } +} |