-
Notifications
You must be signed in to change notification settings - Fork 0
/
alternate_test.go
63 lines (52 loc) · 1.41 KB
/
alternate_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
63
package jq
import "testing"
func TestAlternate(tb *testing.T) {
b := &Buffer{}
root := b.appendVal(obj{
"a",
arr{},
"b",
arr{1, nil, false, 2},
"c",
arr{nil, false},
"d", 5,
})
testIter(tb, NewAlternate(NewQuery("a", Iter{}), NewQuery("b", Iter{})), b, root, []any{1, nil, false, 2})
testIter(tb, NewAlternate(NewQuery("b", Iter{}), NewQuery("d")), b, root, []any{1, 2})
testIter(tb, NewAlternate(NewQuery("c", Iter{}), NewQuery("d")), b, root, []any{5})
}
func TestAlternatePath(tb *testing.T) {
b := &Buffer{}
ka := b.appendVal("a")
kb := b.appendVal("b")
kc := b.appendVal("c")
kd := b.appendVal("d")
ra := b.appendVal(arr{})
rb := b.appendVal(arr{1, nil, false, 2})
rc := b.appendVal(arr{nil, false})
rd := b.appendVal(5)
r0 := b.appendVal(obj{
ka, ra,
kb, rb,
kc, rc,
kd, rd,
})
testIterPath(tb, NewAlternate(NewQuery("a", Iter{}), NewQuery("b", Iter{})), b, r0,
[]any{1, nil, false, 2},
[]NodePath{
{psk(r0, 1, kb), ps(rb, 0)},
{psk(r0, 1, kb), ps(rb, 1)},
{psk(r0, 1, kb), ps(rb, 2)},
{psk(r0, 1, kb), ps(rb, 3)},
})
testIterPath(tb, NewAlternate(NewQuery("b", Iter{}), NewQuery("d")), b, r0,
[]any{1, 2},
[]NodePath{
{psk(r0, 1, kb), ps(rb, 0)},
{psk(r0, 1, kb), ps(rb, 3)},
})
testIterPath(tb, NewAlternate(NewQuery("c", Iter{}), NewQuery("d")), b, r0, []any{5}, []NodePath{{psk(r0, 3, kd)}})
if tb.Failed() {
tb.Logf("buffer:\n%s", b.Dump())
}
}