-
Notifications
You must be signed in to change notification settings - Fork 3
/
lexer_test.go
92 lines (69 loc) · 2.21 KB
/
lexer_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
85
86
87
88
89
90
91
92
package sexp
import (
"github.com/bmizerany/assert"
"testing"
)
func TestCanonicalLexer(t *testing.T) {
l := NewLexer([]byte("(3:foo3:bar(3:baz))"))
item := l.Next()
assert.Equal(t, "(", string(item.Value))
assert.Equal(t, ItemBracketLeft, item.Type)
item = l.Next()
assert.Equal(t, "foo", string(item.Value))
assert.Equal(t, ItemVerbatim, item.Type)
item = l.Next()
assert.Equal(t, "bar", string(item.Value))
assert.Equal(t, ItemVerbatim, item.Type)
item = l.Next()
assert.Equal(t, "(", string(item.Value))
assert.Equal(t, ItemBracketLeft, item.Type)
item = l.Next()
assert.Equal(t, "baz", string(item.Value))
assert.Equal(t, ItemVerbatim, item.Type)
item = l.Next()
assert.Equal(t, ")", string(item.Value))
assert.Equal(t, ItemBracketRight, item.Type)
item = l.Next()
assert.Equal(t, ")", string(item.Value))
assert.Equal(t, ItemBracketRight, item.Type)
item = l.Next()
assert.Equal(t, ItemEOF, item.Type)
}
func TestLexer(t *testing.T) {
l := NewLexer([]byte(`(foo "bar baz" (6:foobar 1 000000000 #fff P4M5S))`))
item := l.Next()
assert.Equal(t, "(", string(item.Value))
assert.Equal(t, ItemBracketLeft, item.Type)
item = l.Next()
assert.Equal(t, "foo", string(item.Value))
assert.Equal(t, ItemToken, item.Type)
item = l.Next()
assert.Equal(t, "bar baz", string(item.Value))
assert.Equal(t, ItemQuote, item.Type)
item = l.Next()
assert.Equal(t, "(", string(item.Value))
assert.Equal(t, ItemBracketLeft, item.Type)
item = l.Next()
assert.Equal(t, "foobar", string(item.Value))
assert.Equal(t, ItemVerbatim, item.Type)
item = l.Next()
assert.Equal(t, "1", string(item.Value))
assert.Equal(t, ItemToken, item.Type)
item = l.Next()
assert.Equal(t, "000000000", string(item.Value))
assert.Equal(t, ItemToken, item.Type)
item = l.Next()
assert.Equal(t, "#fff", string(item.Value))
assert.Equal(t, ItemToken, item.Type)
item = l.Next()
assert.Equal(t, "P4M5S", string(item.Value))
assert.Equal(t, ItemToken, item.Type)
item = l.Next()
assert.Equal(t, ")", string(item.Value))
assert.Equal(t, ItemBracketRight, item.Type)
item = l.Next()
assert.Equal(t, ")", string(item.Value))
assert.Equal(t, ItemBracketRight, item.Type)
item = l.Next()
assert.Equal(t, ItemEOF, item.Type)
}