-
Notifications
You must be signed in to change notification settings - Fork 2
/
stringuntil_test.go
40 lines (37 loc) · 952 Bytes
/
stringuntil_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
package parse_test
import (
"testing"
"github.com/a-h/parse"
)
func TestStringUntil(t *testing.T) {
tests := []ParserTest[string]{
{
name: "StringUntil: success",
input: "ABCDEF",
parser: parse.StringUntil(parse.String("D")),
expectedMatch: "ABC",
expectedOK: true,
},
{
name: "StringUntil: fail, reached EOF before delimiter was found",
input: "ABCDEF",
parser: parse.StringUntil(parse.String("G")),
expectedOK: false,
},
{
name: "StringUntilEOF: stop at the delimiter if it's there",
input: "ABCDEF",
parser: parse.StringUntilEOF(parse.String("F")),
expectedMatch: "ABCDE",
expectedOK: true,
},
{
name: "StringUntilEOF: allow EOF",
input: "ABCDEF",
parser: parse.StringUntilEOF(parse.String("G")),
expectedMatch: "ABCDEF",
expectedOK: true,
},
}
RunParserTests(t, tests)
}