-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_test.go
60 lines (53 loc) · 967 Bytes
/
token_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
package tpl
import (
"testing"
)
func TestTokens(tt *testing.T) {
for i, t := range tokens {
if t == "" {
continue
}
if i > 20 {
n := len(t)
if n < 3 {
tt.Fatal("invalid token:", i, t)
}
if i < 0x80 {
if t[0] != '\'' || t[n-1] != '\'' {
tt.Fatal("invalid token:", i, t)
}
if n != 3 || t[1] != byte(i) {
tt.Fatal("invalid token:", i, t)
}
} else {
if t[0] != '"' || t[n-1] != '"' {
tt.Fatal("invalid token:", i, t)
}
}
}
}
}
func TestToken(t *testing.T) {
if operator_beg != 0x80 {
t.Fatal("operator_beg != 0x80", int(operator_beg))
}
s := new(Scanner)
if s.Ttol(LPAREN) != "'('" {
t.Fatal("LPAREN")
}
if s.Ttol(IDENT) != "IDENT" {
t.Fatal("IDENT")
}
if s.Ttol(ADD_ASSIGN) != "\"+=\"" {
t.Fatal("ADD_ASSIGN")
}
if s.Ltot("\"++\"") != INC {
t.Fatal("++")
}
if s.Ltot("')'") != RPAREN {
t.Fatal(")")
}
if s.Ltot("COMMENT") != COMMENT {
t.Fatal("COMMENT")
}
}