-
Notifications
You must be signed in to change notification settings - Fork 2
/
scan_test.go
122 lines (113 loc) · 5.41 KB
/
scan_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package gs2
import (
"testing"
)
func TestScanner(t *testing.T) {
for _, test := range scanTestTable {
s := newScanner()
var steps []int
for _, b := range []byte(test.data) {
steps = append(steps, s.step(s, b))
}
if len(steps) != len(test.expected) {
t.Errorf("Number of steps doesn't match. Expected: %d, but got %d\n", len(test.expected), len(steps))
}
for i := 0; i < min(len(steps), len(test.expected)); i++ {
if steps[i] != test.expected[i] {
t.Errorf("expected %d, but got %d", test.expected[i], steps[i])
}
}
}
}
var scanTestTable = []struct {
data string
expected []int
}{
{`a`,
[]int{
scanError,
},
},
{`##Block1
#Att1=val1
#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1#Att1=val1#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1
#Att1=val1
#Att2=val2
##Block2
#Att1=val1
#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanSkipSpace,
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1#Att1=val1#Att2=val2##Block2#Att1=val1#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1
#Att1=< val1 val2 val3 >
#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue,
scanArrayStart, scanArraySeparator, scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator, scanArrayEnd, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1#Att1=< val1 val2 val3 >#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue,
scanArrayStart, scanArraySeparator, scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator, scanArrayEnd,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
{`##Block1
#Att1=<val1 val2 val3>
#Att2=val2`,
[]int{
scanHash, scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanContinue, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue,
scanArrayStart, scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArraySeparator,
scanContinue, scanContinue, scanContinue, scanContinue, scanArrayEnd, scanSkipSpace,
scanHash, scanContinue, scanContinue, scanContinue, scanContinue, scanBeginValue, scanContinue, scanContinue, scanContinue, scanContinue,
},
},
}
func min(a, b int) int {
if a < b {
return a
}
return b
}