diff options
author | NeonXP <i@neonxp.dev> | 2022-11-16 05:11:19 +0300 |
---|---|---|
committer | NeonXP <i@neonxp.dev> | 2022-11-16 05:11:19 +0300 |
commit | a321bfe7b2f6db5078de7b2e5ed5ddcccd65f319 (patch) | |
tree | d11c187bceee610a7843463949df128569142680 /json_test.go |
initial commit
Diffstat (limited to 'json_test.go')
-rw-r--r-- | json_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/json_test.go b/json_test.go new file mode 100644 index 0000000..93ce097 --- /dev/null +++ b/json_test.go @@ -0,0 +1,67 @@ +package json + +import ( + "reflect" + "testing" + + "go.neonxp.dev/json/model" +) + +func TestQuery(t *testing.T) { + type args struct { + json string + query string + } + tests := []struct { + name string + args args + want *model.Node + wantErr bool + }{ + { + name: "Complex", + args: args{ + json: `{ + "key1": "value1", + "key2": [ + "item 1", + "item 2", + "item 3", + "item 4", + "item 5", + "item 6", + { + "status": "invalid" + }, + { + "status": "valid", + "embededArray": [ + "not target", + "not target", + "not target", + "target", + "not target", + "not target", + ] + } + ] + }`, + query: "key2.7.embededArray.3", + }, + want: model.NewNode("target"), + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := Query(tt.args.json, tt.args.query) + if (err != nil) != tt.wantErr { + t.Errorf("Query() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Query() = %v, want %v", got, tt.want) + } + }) + } +} |