-
Notifications
You must be signed in to change notification settings - Fork 2
/
until_test.go
52 lines (49 loc) · 1.44 KB
/
until_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
package parse_test
import (
"testing"
"github.com/a-h/parse"
)
func TestUntil(t *testing.T) {
tests := []ParserTest[[]string]{
{
name: "Until: success",
input: "ABCDEF",
parser: parse.Until(parse.AnyRune, parse.String("D")),
expectedMatch: []string{"A", "B", "C"},
expectedOK: true,
},
{
name: "Until: fail, reached EOF before delimiter was found",
input: "ABCDEF",
parser: parse.Until(parse.AnyRune, parse.String("G")),
expectedOK: false,
},
{
name: "UntilEOF: stop at the delimiter if it's there",
input: "ABCDEF",
parser: parse.UntilEOF(parse.AnyRune, parse.String("F")),
expectedMatch: []string{"A", "B", "C", "D", "E"},
expectedOK: true,
},
{
name: "UntilEOF: allow EOF",
input: "ABCDEF",
parser: parse.UntilEOF(parse.AnyRune, parse.String("G")),
expectedMatch: []string{"A", "B", "C", "D", "E", "F"},
expectedOK: true,
},
{
name: "Until: return an error on primary failure",
input: "ABCDEF",
parser: parse.Until(parse.Parser[string](expectErrorParser{}), parse.AnyRune),
expectedErr: errTestParseError,
},
{
name: "Until: return an error on delimiter failure",
input: "ABCDEF",
parser: parse.Until(parse.AnyRune, parse.Parser[string](expectErrorParser{})),
expectedErr: errTestParseError,
},
}
RunParserTests(t, tests)
}