-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimes_test.go
88 lines (85 loc) · 2.19 KB
/
times_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
package parse_test
import (
"testing"
"github.com/a-h/parse"
)
func TestTimes(t *testing.T) {
tests := []ParserTest[[]string]{
{
name: "Times: no match",
input: "ABCDEF",
parser: parse.Times(2, parse.String("A")),
expectedOK: false,
},
{
name: "Times: matches",
input: "AAAA",
parser: parse.Times(3, parse.String("A")),
expectedMatch: []string{"A", "A", "A"},
expectedOK: true,
},
{
name: "Repeat: must be at least 1, and take up to 5",
input: "AAAA",
parser: parse.Repeat(1, 5, parse.String("A")),
expectedMatch: []string{"A", "A", "A", "A"},
expectedOK: true,
},
{
name: "Repeat: min of 4, max of 5 - no match",
input: "AAA",
parser: parse.Repeat(4, 5, parse.String("A")),
expectedOK: false,
},
{
name: "Repeat: min of 0, max of 2 - matches",
input: "AAA",
parser: parse.Repeat(0, 2, parse.String("A")),
expectedMatch: []string{"A", "A"},
expectedOK: true,
},
{
name: "AtMost: success",
input: "AAA",
parser: parse.AtMost(2, parse.String("A")),
expectedMatch: []string{"A", "A"},
expectedOK: true,
},
{
name: "AtLeast: success",
input: "AAA",
parser: parse.AtLeast(2, parse.String("A")),
expectedMatch: []string{"A", "A", "A"},
expectedOK: true,
},
{
name: "ZeroOrMore: nothing to get",
input: "BB",
parser: parse.ZeroOrMore(parse.String("A")),
expectedMatch: nil,
expectedOK: true,
},
{
name: "ZeroOrMore: something to get",
input: "AA",
parser: parse.ZeroOrMore(parse.String("A")),
expectedMatch: []string{"A", "A"},
expectedOK: true,
},
{
name: "OneOrMore: nothing to get",
input: "BB",
parser: parse.OneOrMore(parse.String("A")),
expectedMatch: nil,
expectedOK: false,
},
{
name: "OneOrMore: something to get",
input: "AA",
parser: parse.OneOrMore(parse.String("A")),
expectedMatch: []string{"A", "A"},
expectedOK: true,
},
}
RunParserTests(t, tests)
}