-
Notifications
You must be signed in to change notification settings - Fork 9
/
state_test.go
50 lines (38 loc) · 1.59 KB
/
state_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
package godnf_test
import (
"testing"
dnf "github.com/brg-liuwei/godnf"
)
func setDelim() {
dnf.SetDelimOfConj(rune('('), rune(')'))
dnf.SetDelimOfSet(rune('{'), rune('}'))
dnf.SetSeparatorOfSet(rune(','))
}
func TestDnfCheck(t *testing.T) {
dnf.SetDebug(false)
setDelim()
checkDnf := func(dnfStr string, noErr bool) {
err := dnf.DnfCheck(dnfStr)
if (err == nil) != noErr {
t.Error("test ", dnfStr, " fail")
}
}
checkDnf("", false) // test dnfStart
checkDnf(" ", false) // test dnfStart
checkDnf("(", false) // test State1
checkDnf("( ", false) // test State1
checkDnf(" [ city in { Beijing }] ", false) // test State1
checkDnf(" (city in{Beijing}) ", true) // test skipString
checkDnf(" ( city in { Beijing }) ", true) // test State2
checkDnf(" ( city not in { Beijing })", true) // test State2
checkDnf(" ( city not on { Beijing })", false) // test State2
checkDnf(" ( city at { Beijing })", false) // test State2
checkDnf("(city in [ Beijing })", false) // test State4
checkDnf("( city in { ShangHai ShenZheng })", false) // test State5
checkDnf("( city in { ShangHai ])", false) // test State6
checkDnf("( city in { ShangHai, ShenZheng ))", false) // test State7
checkDnf("(city in {SH} and gender not in { female}) or (age in {3, 5})", true)
checkDnf("(city in {SH} and gender not in { female}) or (age in {3, 5} and city in {HZ})", true)
checkDnf("(city in {SH} and city not in { BJ }) or (age in {3, 5} and city in {HZ})", false)
checkDnf("(city in {SH}) or (age in {3, 5} and city in {HZ}", false)
}