-
Notifications
You must be signed in to change notification settings - Fork 0
/
pick_test.go
62 lines (47 loc) · 1.46 KB
/
pick_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jq
import "testing"
func TestPick(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(obj{"a", arr{obj{"a", 1}, obj{"a", 2, "b", 3}}})
testOne(tb, NewPick(NewQuery("a", Iter{}, "a")), b, r, obj{"a", arr{obj{"a", 1}, obj{"a", 2}}})
}
func TestPickArray(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(arr{"a", "b", "c", "d", "e"})
testOne(tb, NewPick(NewMulti(-5, 1, 4, 5)), b, r, arr{"a", "b", nil, nil, "e", nil})
}
func TestPickMap(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(obj{"a", "b", "c", "d", "e", "f"})
testOne(tb, NewPick(NewMulti("e", "a")), b, r, obj{"e", "f", "a", "b"})
}
func TestPickMapAdd(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(obj{"a", "b", "c", "d", "e", "f"})
testOne(tb, NewPick(NewMulti("c", "g", "g")), b, r, obj{"c", "d", "g", nil})
}
func TestPickIterAdd(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(obj{"a", arr{obj{"a", 1}, obj{"a", 2, "b", 3}}})
testOne(tb, NewPick(NewQuery("a", Iter{}, "b")), b, r, obj{"a", arr{obj{"b", nil}, obj{"b", 3}}})
}
func TestPickIterAppend(tb *testing.T) {
b := NewBuffer()
r := b.appendVal(obj{"a", arr{obj{"a", 1}, obj{"a", 2, "b", 3}}})
testOne(tb, NewPick(NewQuery("a", NewMulti(Iter{}, 3), "b")), b, r, obj{"a", arr{obj{"b", nil}, obj{"b", 3}, nil, obj{"b", nil}}})
}
func TestPickCreate(tb *testing.T) {
b := NewBuffer()
r := Null
testOne(tb, NewPick(NewQuery(
"a",
3,
"b",
)), b, r, obj{
"a",
arr{
nil, nil, nil,
obj{"b", nil},
},
})
}