-
Notifications
You must be signed in to change notification settings - Fork 2
/
reftest_test.go
44 lines (40 loc) · 1.16 KB
/
reftest_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
// This file is part of marionette-go
//
// marionette-go is distributed in two licenses: The Mozilla Public License,
// v. 2.0 and the GNU Lesser Public License.
//
// marionette-go is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.
//
// See License.txt for further information.
package marionette
import (
"encoding/json"
"strconv"
"testing"
)
func TestRefEncode(t *testing.T) {
cases := map[string]ReftestRefList{
`[["A",[["B",[],"!="]],"=="]]`: (ReftestRefList{}).
Or("B", "!=").And("A", "=="),
`[["A",[["B",[],"!="],["C",[],"!="]],"=="]]`: (ReftestRefList{}).
Or("B", "!=").Or("C", "!=").And("A", "=="),
`[["A",[["B",[],"!="]],"=="],["D",[],"=="]]`: (ReftestRefList{}).
Or("B", "!=").And("A", "==").Or("D", "=="),
}
cnt := 0
for expected, rules := range cases {
cnt++
t.Run("#"+strconv.Itoa(cnt), func(t *testing.T) {
data, err := json.Marshal(rules)
if err != nil {
t.Fatalf("cannot marshal rule: %s", err)
}
str := string(data)
if str != expected {
t.Fatalf("unexpected result: %s", str)
}
})
}
}