-
Notifications
You must be signed in to change notification settings - Fork 20
/
nfa_test.go
84 lines (77 loc) · 1.77 KB
/
nfa_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
package quamina
import (
"fmt"
"testing"
"unsafe"
)
// TestArrayBehavior is here prove that (a) you can index a map with an array and
// the indexing actually relies on the values in the array. This has nothing to do with
// Quamina, but I'm leaving it here because I had to write this stupid test after failing
// to find a straightforward question of whether this works as expected anywhere in the
// Golang docs.
func TestArrayBehavior(t *testing.T) {
type gpig [4]int
pigs := []gpig{
{1, 2, 3, 4},
{4, 3, 2, 1},
}
nonPigs := []gpig{
{3, 4, 3, 4},
{99, 88, 77, 66},
}
m := make(map[gpig]bool)
for _, pig := range pigs {
m[pig] = true
}
for _, pig := range pigs {
_, ok := m[pig]
if !ok {
t.Error("missed pig")
}
}
pigs[0][0] = 111
pigs[1][3] = 777
pigs = append(pigs, nonPigs...)
for _, pig := range pigs {
_, ok := m[pig]
if ok {
t.Error("mutant pig")
}
}
newPig := gpig{1, 2, 3, 4}
_, ok := m[newPig]
if !ok {
t.Error("Newpig")
}
}
func TestFocusedMerge(t *testing.T) {
shellStyles := []string{
"a*b",
"ab*",
"*ab",
}
var automata []*smallTable
var matchers []*fieldMatcher
for _, shellStyle := range shellStyles {
str := `"` + shellStyle + `"`
automaton, matcher := makeShellStyleFA([]byte(str), &nullPrinter{})
automata = append(automata, automaton)
matchers = append(matchers, matcher)
}
var cab uintptr
for _, mm := range matchers {
uu := uintptr(unsafe.Pointer(mm))
cab = cab ^ uu
}
merged := newSmallTable()
for _, automaton := range automata {
merged = mergeFAs(merged, automaton, sharedNullPrinter)
s := statsAccum{
fmVisited: make(map[*fieldMatcher]bool),
vmVisited: make(map[*valueMatcher]bool),
stVisited: make(map[*smallTable]bool),
}
faStats(merged, &s)
fmt.Println(s.stStats())
}
}