-
Notifications
You must be signed in to change notification settings - Fork 2
/
rune_test.go
85 lines (82 loc) · 1.8 KB
/
rune_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
package parse_test
import (
"testing"
"unicode"
"github.com/a-h/parse"
)
func TestRuneWhere(t *testing.T) {
tests := []ParserTest[string]{
{
name: "RuneWhere: no match",
input: "ABCDEF",
parser: parse.RuneWhere(func(r rune) bool { return r == 'a' }),
expectedMatch: "",
expectedOK: false,
},
{
name: "RuneWhere: match",
input: "ABCDEF",
parser: parse.RuneWhere(func(r rune) bool {
return unicode.IsUpper(r)
}),
expectedMatch: "A",
expectedOK: true,
},
{
name: "AnyRune: match",
input: "ABCDEF",
parser: parse.AnyRune,
expectedMatch: "A",
expectedOK: true,
},
{
name: "RuneIn: no match",
input: "ABCDEF",
parser: parse.RuneIn("123"),
expectedMatch: "",
expectedOK: false,
},
{
name: "RuneIn: match",
input: "ABCDEF",
parser: parse.RuneIn("CBA"),
expectedMatch: "A",
expectedOK: true,
},
{
name: "RuneNotIn: no match",
input: "ABCDEF",
parser: parse.RuneNotIn("ABC"),
expectedMatch: "",
expectedOK: false,
},
{
name: "RuneNotIn: match",
input: "ABCDEF",
parser: parse.RuneNotIn("123"),
expectedMatch: "A",
expectedOK: true,
},
{
name: "RuneInRanges: match",
input: " ",
parser: parse.RuneInRanges(unicode.White_Space),
expectedMatch: " ",
expectedOK: true,
},
{
name: "RuneInRanges: no match",
input: " ",
parser: parse.RuneInRanges(unicode.Han),
expectedOK: false,
},
{
name: "Letter: match",
input: "a",
parser: parse.Letter,
expectedMatch: "a",
expectedOK: true,
},
}
RunParserTests(t, tests)
}