-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuilder_test.go
61 lines (54 loc) · 1.29 KB
/
builder_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
package rd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExit_NilResult(t *testing.T) {
b := NewBuilder(nil)
b.Enter("")
assert.Panics(t, func() {
b.Exit(nil)
}, "Exit result must be non-nil")
}
func TestExit_FinalEleAndDebugTree(t *testing.T) {
b := NewBuilder(nil)
b.Enter("root")
assert.Equal(t, ele{}, b.finalEle)
assert.Nil(t, b.finalDebugTree)
root := b.stack.peek()
rootDebugTree := b.debugStack.peek()
result := true
b.Exit(&result)
assert.Equal(t, root, b.finalEle)
assert.Equal(t, rootDebugTree, b.finalDebugTree)
}
func TestExit_FinalErr(t *testing.T) {
b := NewBuilder(nil)
b.Enter("root")
assert.Nil(t, b.finalErr)
result := false
b.Exit(&result)
assert.NotNil(t, b.finalErr)
}
func TestExit_AddToParent(t *testing.T) {
b := NewBuilder(nil)
b.Enter("root")
root := b.stack.peek()
rootDebugTree := b.debugStack.peek()
b.Enter("child")
child := b.stack.peek()
childDebugTree := b.debugStack.peek()
result := true
b.Exit(&result)
assert.Contains(t, root.nonTerm.Subtrees, child.nonTerm)
assert.Contains(t, rootDebugTree.subtrees, childDebugTree)
}
func TestExit_FalseResult(t *testing.T) {
b := NewBuilder(nil)
b.current = 1
b.Enter("")
b.current = 2
result := false
b.Exit(&result)
assert.Equal(t, 1, b.current, "current must be reset")
}