-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlexer_test.go
84 lines (73 loc) · 1.85 KB
/
lexer_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 vdf
import (
"strings"
"testing"
)
// Ensure the scanner can scan tokens correctly.
func TestScanner_Scan(t *testing.T) {
var tests = []struct {
s string
tok Token
lit string
}{
// Special tokens (EOF, ILLEGAL, WS)
{s: ``, tok: EOF},
{s: `#`, tok: Illegal, lit: `#`},
{s: ` `, tok: WS, lit: " "},
{s: "\t", tok: WS, lit: "\t"},
{s: "\n", tok: WS, lit: "\n"},
{s: "\r", tok: WS, lit: "\r"},
// Misc characters
{s: `{`, tok: CurlyBraceOpen, lit: "{"},
{s: `}`, tok: CurlyBraceClose, lit: "}"},
{s: `"`, tok: QuotationMark, lit: "\""},
{s: `\`, tok: EscapeSequence, lit: "\\"},
{s: "//", tok: CommentDoubleSlash, lit: "//"},
// Identifiers
{s: `foo`, tok: Ident, lit: `foo`},
{s: `Zx12_3U_-`, tok: Ident, lit: `Zx12_3U_`},
}
for i, tt := range tests {
s := NewScanner(strings.NewReader(tt.s))
tok, lit := s.Scan(false)
if tt.tok != tok {
t.Errorf("%d. %q token mismatch: exp=%q got=%q <%q>", i, tt.s, tt.tok, tok, lit)
} else if tt.lit != lit {
t.Errorf("%d. %q literal mismatch: exp=%q got=%q", i, tt.s, tt.lit, lit)
}
}
}
func FuzzScanner_ScanWithoutWhitespace(f *testing.F) {
testcases := []string{
// Special tokens (EOF, ILLEGAL, WS)
``, `#`, ` `, "\t", "\n", "\r",
// Misc characters
`{`, `}`, `"`, `\`, "//",
// Identifiers
`foo`, `Zx12_3U_-`,
}
for _, tc := range testcases {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, input string) {
s := NewScanner(strings.NewReader(input))
s.Scan(false)
})
}
func FuzzScanner_ScanWithWhitespace(f *testing.F) {
testcases := []string{
// Special tokens (EOF, ILLEGAL, WS)
``, `#`, ` `, "\t", "\n", "\r",
// Misc characters
`{`, `}`, `"`, `\`, "//",
// Identifiers
`foo`, `Zx12_3U_-`,
}
for _, tc := range testcases {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, input string) {
s := NewScanner(strings.NewReader(input))
s.Scan(true)
})
}