6 "github.com/mjl-/mox/store"
9func TestNumSetContains(t *testing.T) {
10 num := func(v uint32) *setNumber {
11 return &setNumber{v, false}
13 star := &setNumber{star: true}
15 check := func(v bool) {
22 ss0 := numSet{true, nil} // "$"
23 check(ss0.containsSeq(1, []store.UID{2}, []store.UID{2}))
24 check(!ss0.containsSeq(1, []store.UID{2}, []store.UID{}))
26 check(ss0.containsUID(1, []store.UID{1}, []store.UID{1}))
27 check(ss0.containsUID(2, []store.UID{1, 2, 3}, []store.UID{2}))
28 check(!ss0.containsUID(2, []store.UID{1, 2, 3}, []store.UID{}))
29 check(!ss0.containsUID(2, []store.UID{}, []store.UID{2}))
31 ss1 := numSet{false, []numRange{{*num(1), nil}}} // Single number 1.
32 check(ss1.containsSeq(1, []store.UID{2}, nil))
33 check(!ss1.containsSeq(2, []store.UID{1, 2}, nil))
35 check(ss1.containsUID(1, []store.UID{1}, nil))
36 check(ss1.containsSeq(1, []store.UID{2}, nil))
37 check(!ss1.containsSeq(2, []store.UID{1, 2}, nil))
40 ss2 := numSet{false, []numRange{{*num(2), star}}}
41 check(ss2.containsSeq(1, []store.UID{2}, nil))
42 check(!ss2.containsSeq(2, []store.UID{2}, nil))
43 check(ss2.containsSeq(2, []store.UID{4, 5}, nil))
44 check(ss2.containsSeq(3, []store.UID{4, 5, 6}, nil))
45 check(!ss2.containsSeq(4, []store.UID{4, 5, 6}, nil))
47 check(ss2.containsUID(2, []store.UID{2}, nil))
48 check(!ss2.containsUID(1, []store.UID{1, 2, 3}, nil))
49 check(ss2.containsUID(3, []store.UID{1, 2, 3}, nil))
50 check(!ss2.containsUID(2, []store.UID{4, 5}, nil))
51 check(!ss2.containsUID(2, []store.UID{1}, nil))
53 check(ss2.containsUID(2, []store.UID{2, 6}, nil))
54 check(ss2.containsUID(6, []store.UID{2, 6}, nil))
57 ss3 := numSet{false, []numRange{{*star, num(2)}}}
58 check(ss3.containsSeq(1, []store.UID{2}, nil))
59 check(!ss3.containsSeq(2, []store.UID{2}, nil))
60 check(ss3.containsSeq(2, []store.UID{4, 5}, nil))
61 check(ss3.containsSeq(3, []store.UID{4, 5, 6}, nil))
62 check(!ss3.containsSeq(4, []store.UID{4, 5, 6}, nil))
64 check(ss3.containsUID(2, []store.UID{2}, nil))
65 check(!ss3.containsUID(1, []store.UID{1, 2, 3}, nil))
66 check(ss3.containsUID(3, []store.UID{1, 2, 3}, nil))
67 check(!ss3.containsUID(2, []store.UID{4, 5}, nil))
68 check(!ss3.containsUID(2, []store.UID{1}, nil))
70 check(ss3.containsUID(2, []store.UID{2, 6}, nil))
71 check(ss3.containsUID(6, []store.UID{2, 6}, nil))
74func TestNumSetInterpret(t *testing.T) {
75 parseNumSet := func(s string) numSet {
77 return p.xnumSet0(true, false)
80 checkEqual := func(uids []store.UID, a, s string) {
82 n := parseNumSet(a).interpretStar(uids)
85 t.Fatalf("%s != %s", ns, s)
89 checkEqual([]store.UID{}, "1:*", "")
90 checkEqual([]store.UID{1}, "1:*", "1")
91 checkEqual([]store.UID{1, 3}, "1:*", "1:3")
92 checkEqual([]store.UID{1, 3}, "4:*", "3")
93 checkEqual([]store.UID{1, 3}, "*:4", "3")
94 checkEqual([]store.UID{2, 3}, "*:4", "3")
95 checkEqual([]store.UID{2, 3}, "*:1", "1:3")
96 checkEqual([]store.UID{2, 3}, "1:*", "1:3")
97 checkEqual([]store.UID{1, 2, 3}, "1,2,3", "1,2,3")
98 checkEqual([]store.UID{}, "1,2,3", "")
99 checkEqual([]store.UID{}, "1:3", "")
100 checkEqual([]store.UID{}, "3:1", "")
102 iter := parseNumSet("1:3").interpretStar([]store.UID{}).newIter()
103 if _, ok := iter.Next(); ok {
104 t.Fatalf("expected immediate end for empty iter")
107 iter = parseNumSet("3:1").interpretStar([]store.UID{1, 2}).newIter()
111 if v0 != 1 || v1 != 2 || ok {
112 t.Fatalf("got %v %v %v, expected 1, 2, false", v0, v1, ok)