-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
63 lines (57 loc) · 1.52 KB
/
parse_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
package parser_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
parser "github.com/lyrise/sprache-go"
"github.com/lyrise/sprache-go/internal"
)
func TestParse(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Parse Spec")
}
var _ = Describe("Parse Test", func() {
Context("RuneFunc Test", func() {
tests := []struct {
name string
input parser.ParserInput
parser parser.Parser[rune]
wantSucceeded bool
wantValue rune
wantRemainder string
}{
{
name: "simple",
input: parser.NewParserInput("a"),
parser: parser.RuneFunc(func(r rune) bool { return r == 'a' }, ""),
wantSucceeded: true,
wantValue: 'a',
wantRemainder: "",
},
{
name: "simple 2",
input: parser.NewParserInput("ab"),
parser: parser.RuneFunc(func(r rune) bool { return r == 'a' }, ""),
wantSucceeded: true,
wantValue: 'a',
wantRemainder: "b",
},
{
name: "simple 3",
input: parser.NewParserInput("ab"),
parser: parser.RuneFunc(func(r rune) bool { return r == 'b' }, ""),
wantSucceeded: false,
wantValue: 0,
wantRemainder: "ab",
},
}
for _, tt := range tests {
It(tt.name, func() {
got := tt.parser(tt.input)
Expect(got.Succeeded).To(Equal(tt.wantSucceeded))
Expect(got.Value).To(internal.EqualCmp(tt.wantValue))
Expect(got.Remainder.String()).To(internal.EqualCmp(tt.wantRemainder))
})
}
})
})