-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpath_test.go
40 lines (31 loc) · 1007 Bytes
/
path_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
package jsonpath
import (
"testing"
"github.com/stretchr/testify/assert"
)
type optest struct {
name string
path string
expected []int
}
var optests = []optest{
optest{"single key (period) ", `$.aKey`, []int{opTypeName}},
optest{"single key (bracket)", `$["aKey"]`, []int{opTypeName}},
optest{"single key (period) ", `$.*`, []int{opTypeNameWild}},
optest{"single index", `$[12]`, []int{opTypeIndex}},
optest{"single key", `$[23:45]`, []int{opTypeIndexRange}},
optest{"single key", `$[*]`, []int{opTypeIndexWild}},
optest{"double key", `$["aKey"]["bKey"]`, []int{opTypeName, opTypeName}},
optest{"double key", `$["aKey"].bKey`, []int{opTypeName, opTypeName}},
}
func TestQueryOperators(t *testing.T) {
as := assert.New(t)
for _, t := range optests {
path, err := parsePath(t.path)
as.NoError(err)
as.EqualValues(len(t.expected), len(path.operators))
for x, op := range t.expected {
as.EqualValues(pathTokenNames[op], pathTokenNames[path.operators[x].typ])
}
}
}