-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmaybe_test.go
38 lines (31 loc) · 947 Bytes
/
maybe_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
/*
(c) 2019 Launix, Inh. Carl-Philip Hänsch
Author: Tim Kluge
Dual licensed with custom aggreements or GPLv3
*/
package packrat
import "testing"
func TestMaybe(t *testing.T) {
input := "Hello"
scanner := NewScanner[int](input, SkipWhitespaceRegex)
helloParser := NewAtomParser(17, "Hello", false, true)
helloAndWorldParser := NewMaybeParser(13, helloParser)
n, err := ParsePartial(helloAndWorldParser, scanner)
if err != nil {
t.Error(err)
} else {
if n.Payload != 17 {
t.Error("Maybe combinator doesn't produce correct payload")
}
}
irregularInput := "Sonne"
irregularScanner := NewScanner[int](irregularInput, SkipWhitespaceRegex)
irregularParser := NewMaybeParser(13, helloParser)
in, ierr := ParsePartial(irregularParser, irregularScanner)
if ierr != nil {
t.Error("Maybe combinator doesn't match irregular input")
}
if in.Payload != 13 {
t.Error("Maybe combinator doesn't produce correct payload")
}
}