-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable-item_test.go
84 lines (71 loc) · 1.69 KB
/
table-item_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package lr0
import (
"testing"
"github.com/vovan-ve/go-lr0-parser/internal/testutils"
)
func TestTableItem_IsEqual(t *testing.T) {
l := newLexer(
NewTerm(tInt, "int").Str("1"),
)
ntDef := NewNT(nSum, "Sum").Is(tInt, tPlus, tInt).Do(calc3AnyNil)
rule1orig := ntDef.GetRules(l)[0]
rule1copy := ntDef.GetRules(l)[0]
s1 := newTableItem(rule1orig)
if s1 != newTableItem(rule1orig) {
t.Fatal("same not equal")
}
if s1 == newTableItem(rule1copy) {
t.Error("different equal")
}
s2 := s1.Shift()
if s1 != newTableItem(rule1orig) {
t.Error("s1 changed")
}
if s2 == s1 {
t.Error("s2 is same")
}
}
func TestTableItem_Navigate(t *testing.T) {
l := newLexer(
NewTerm(tInt, "int").Str("1"),
NewTerm(tPlus, "plus").Str("+"),
)
ntDef := NewNT(nSum, "Sum").Is(nVal, tPlus, tInt).Do(calc3AnyNil)
r := ntDef.GetRules(l)[0]
i0 := newTableItem(r)
if i0.Expected() != nVal {
t.Error("i0 expect() wrong: ", i0.Expected())
}
if !i0.HasFurther() {
t.Error("i0 has further wrong")
}
i1 := i0.Shift()
if i1.Expected() != tPlus {
t.Error("i1 expect() wrong: ", i1.Expected())
}
if !i1.HasFurther() {
t.Error("i1 has further wrong")
}
i2 := i1.Shift()
if i2.Expected() != tInt {
t.Error("i2 expect() wrong: ", i2.Expected())
}
if !i2.HasFurther() {
t.Error("i2 has further wrong")
}
i3 := i2.Shift()
if i3.Expected() != InvalidId {
t.Error("i3 expect() wrong: ", i3.Expected())
}
if i3.HasFurther() {
t.Error("i3 has further wrong")
}
t.Run("shift in the end", func(t *testing.T) {
defer testutils.ExpectPanicError(t, nil, func(t *testing.T, err error) {
if err.Error() != "bad usage: internal error" {
t.Error("another error", err)
}
})
i3.Shift()
})
}