-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilder_test.go
86 lines (77 loc) · 2.77 KB
/
builder_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package qualify
import (
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("Builder", func() {
var subject *Builder
BeforeEach(func() {
subject = seedBuilder()
})
It("should add rules", func() {
Expect(subject.outcomes).To(Equal(map[int]int{7: 0, 8: 1}))
Expect(subject.fields).To(Equal(fieldSet{
FieldCountry: {},
FieldBrowser: {},
FieldOS: {},
FieldAttrs: {},
}))
Expect(subject.explicit.Human()).To(Equal(map[Field][]int{
FieldCountry: {0},
FieldBrowser: nil,
FieldOS: {1},
FieldAttrs: {0},
}))
Expect(subject.oneOf.Human()).To(Equal(map[fieldValue][]int{
{Field: FieldCountry, Value: strDict.Add("gbr")}: {0},
{Field: FieldCountry, Value: strDict.Add("irl")}: {0},
{Field: FieldAttrs, Value: 33}: {0},
{Field: FieldAttrs, Value: 34}: {0},
{Field: FieldAttrs, Value: 55}: {0},
{Field: FieldAttrs, Value: 56}: {0},
{Field: FieldOS, Value: strDict.Add("android")}: {1},
{Field: FieldOS, Value: strDict.Add("ios")}: {1},
}))
Expect(subject.oneOfX.Human()).To(Equal(map[int]map[Field]int{
7: {FieldCountry: 1, FieldAttrs: 2},
8: {FieldOS: 1},
}))
Expect(subject.noneOf.Human()).To(Equal(map[fieldValue][]int{
{Field: FieldBrowser, Value: strDict.Add("safari")}: {0},
{Field: FieldCountry, Value: strDict.Add("ger")}: {1},
{Field: FieldCountry, Value: strDict.Add("fra")}: {1},
}))
})
It("should compile qualifier", func() {
qfy := subject.Compile()
Expect(qfy.outcomes).To(Equal([]int{7, 8}))
Expect(qfy.implicit.Human()).To(Equal(map[Field][]int{
FieldCountry: {1},
FieldBrowser: {0, 1},
FieldOS: {0},
FieldAttrs: {1},
}))
Expect(qfy.oneOf.Human()).To(Equal(map[fieldValue][]int{
{Field: FieldCountry, Value: strDict.Add("gbr")}: {0},
{Field: FieldCountry, Value: strDict.Add("irl")}: {0},
{Field: FieldAttrs, Value: 33}: {0},
{Field: FieldAttrs, Value: 34}: {0},
{Field: FieldAttrs, Value: 55}: {0},
{Field: FieldAttrs, Value: 56}: {0},
{Field: FieldOS, Value: strDict.Add("android")}: {1},
{Field: FieldOS, Value: strDict.Add("ios")}: {1},
}))
Expect(qfy.oneOfX.Human()).To(Equal(map[int]map[Field]int{
7: {FieldAttrs: 2},
}))
Expect(qfy.noneOf.Human()).To(Equal(map[fieldValue][]int{
{Field: FieldBrowser, Value: strDict.Add("safari")}: {0},
{Field: FieldCountry, Value: strDict.Add("ger")}: {1},
{Field: FieldCountry, Value: strDict.Add("fra")}: {1},
}))
})
It("should snapshot on compile", func() {
Expect(subject.Compile()).To(BeAssignableToTypeOf(&Qualifier{}))
Expect(subject.Require(9, FieldAttrs, OneOf(77, 78))).To(BeFalse())
})
})