-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoken_test.go
More file actions
35 lines (29 loc) · 994 Bytes
/
token_test.go
File metadata and controls
35 lines (29 loc) · 994 Bytes
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
package rule
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestTokenize 测试 token 生成
func TestTokenize(t *testing.T) {
program := "(or (and 'c0 <= -9' 'c1 >= -10') 'c3 = 0')"
tokens := tokenize(program)
assert.Equal(t, leftParenthesisToken, tokens.shift().tokenType)
assert.Equal(t, orToken, tokens.shift().tokenType)
assert.Equal(t, leftParenthesisToken, tokens.shift().tokenType)
assert.Equal(t, andToken, tokens.shift().tokenType)
assert.Equal(t, "c0 <= -9", tokens.shift().buf)
}
// TestTokenize 测试 symbol
func TestTokenize2(t *testing.T) {
program := "var"
tokens := tokenize(program)
assert.Equal(t, symbolToken, tokens.shift().tokenType)
}
// TestTokenize 测试 symbol
func TestTokenize3(t *testing.T) {
program := "(let r1 'c0 <= -9)"
tokens := tokenize(program)
assert.Equal(t, leftParenthesisToken, tokens.shift().tokenType)
assert.Equal(t, letToken, tokens.shift().tokenType)
assert.Equal(t, symbolToken, tokens.shift().tokenType)
}