-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
63 lines (60 loc) · 1.44 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 combinator
import (
"testing"
)
func TestParse(t *testing.T) {
tests := map[string]string{
"x": "x",
"(x)": "x",
"((x))": "x",
"xx": "xx",
"(x)x": "xx",
"((x)x)": "xx",
"((x)(x))": "xx",
"x(x)": "xx",
"xxx": "xxx",
"(xxx)": "xxx",
"((x)xx)": "xxx",
"(((x)x)x)": "xxx",
"((x)(xx))": "x(xx)",
"x(xx)": "x(xx)",
"x((x)x)": "x(xx)",
"(x(xx))": "x(xx)",
"xx(xx)": "xx(xx)",
"x(xx)x": "x(xx)x",
}
for statement, expectedResult := range tests {
t.Run(statement, func(t *testing.T) {
tree := parse(statement)
actualResult := unparse(tree)
if expectedResult != actualResult {
t.Errorf("parsed statement %s incorrectly, expected %s but got %s", statement, expectedResult, actualResult)
}
})
}
}
func TestWellDefined(t *testing.T) {
tests := map[string]bool{
"x": true,
"(x)": true,
"(xy)": true,
"((x))": true,
"(x(x))": true,
"": false,
"()": false,
"x()": false,
"(()": false,
")(": false,
"(x(": false,
"(x))((x)": false,
}
for statement, expectedResult := range tests {
t.Run(statement, func(t *testing.T) {
err := isWellDefined(statement)
actualResult := err == nil
if expectedResult != actualResult {
t.Errorf("tested well-definedness for statement %s incorrectly, expected %t but got %t", statement, expectedResult, actualResult)
}
})
}
}