-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgearley_test.go
53 lines (42 loc) · 966 Bytes
/
gearley_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
package gearley
import (
"testing"
)
var T = NonTerminal("T")
var A = Terminal('a')
var B = Terminal('b')
func Test_parse_Aabb(t *testing.T) {
g := Grammar(
Rule(T, A, B), // T -> 'a' 'b'
Rule(T, A, T, B), // T -> 'a' T 'b'
)
g.Parse("aabb")
}
func Test_stateSet_putItem(t *testing.T) {
ruleA := Rule(T, A)
ruleB := Rule(T, B)
s := newStateSet()
if s.length() != 0 {
t.Errorf("length not 0: %v", s)
}
item1a := &eitem{rule: ruleA, dot: 0, index: 0}
item1b := &eitem{rule: ruleA, dot: 0, index: 0}
item2a := &eitem{rule: ruleB, dot: 0, index: 0}
//item2b := &eitem{rule: Rule(T, B), dot: 0, index: 0}
s.putItem(item1a)
if s.length() != 1 {
t.Errorf("length not 1: %v", s)
}
s.putItem(item1b)
if s.length() != 1 {
t.Errorf("length not 1: %v", s)
}
s.putItem(item2a)
if s.length() != 2 {
t.Errorf("length not 2: %v", s)
}
//s.putItem(item2b)
//if s.length() != 2 {
// t.Errorf("length not 2: %v", s)
//}
}