-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
42 lines (39 loc) · 928 Bytes
/
parse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package query
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestParseString(t *testing.T) {
t.Run("success", func(t *testing.T) {
tests := map[string]struct {
src string
expected *Query
}{
"empty": {
src: "",
expected: New(),
},
"key[index][index].key": {
src: "a[0][1].b",
expected: New().Key("a").Index(0).Index(1).Key("b"),
},
"$.key[index][key].key": {
src: "$.a[0]['\\'1.0\\''].b",
expected: New().Root().Key("a").Index(0).Key("'1.0'").Key("b"),
},
}
opt := cmp.AllowUnexported(Query{}, Key{}, Index{})
for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
got, err := ParseString(test.src)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if diff := cmp.Diff(test.expected, got, opt); diff != "" {
t.Errorf("differs: (-want +got)\n%s", diff)
}
})
}
})
}