forked from BatchLabs/charlatan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_test.go
64 lines (53 loc) · 1.62 KB
/
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
61
62
63
64
package charlatan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTokenIsEnd(t *testing.T) {
assert.True(t, token{Type: tokEnd}.isEnd())
}
func TestTokenIsNumeric(t *testing.T) {
assert.True(t, token{Type: tokInt}.isNumeric())
assert.True(t, token{Type: tokFloat}.isNumeric())
}
func TestTokenIsKeyword(t *testing.T) {
assert.True(t, token{Type: tokSelect}.isKeyword())
assert.True(t, token{Type: tokFrom}.isKeyword())
assert.True(t, token{Type: tokWhere}.isKeyword())
assert.True(t, token{Type: tokStarting}.isKeyword())
for _, ty := range []tokenType{
tokSelect, tokFrom, tokWhere, tokStarting,
} {
assert.True(t, token{Type: ty}.isKeyword())
}
}
func TestTokenIsOperator(t *testing.T) {
for _, ty := range []tokenType{
tokAnd, tokOr, tokEq, tokNeq, tokLt, tokLte, tokGt, tokGte,
} {
assert.True(t, token{Type: ty}.isOperator())
}
}
func TestTokenIsLogicalOperator(t *testing.T) {
for _, ty := range []tokenType{tokAnd, tokOr} {
assert.True(t, token{Type: ty}.isLogicalOperator())
}
}
func TestTokenIsComparisonOperator(t *testing.T) {
for _, ty := range []tokenType{
tokEq, tokNeq, tokLt, tokLte, tokGt, tokGte,
} {
assert.True(t, token{Type: ty}.isComparisonOperator())
}
}
func TestTokenTypeString(t *testing.T) {
for _, ty := range []tokenType{
tokField, tokInt, tokFloat, tokTrue, tokFalse, tokNull, tokSelect,
tokFrom, tokWhere, tokStarting, tokAt, tokAnd, tokOr, tokEq, tokNeq,
tokLt, tokLte, tokGt, tokGte, tokLeftParenthesis, tokRightParenthesis,
tokComma, tokBetween, tokEnd,
} {
assert.NotEqual(t, "", ty.String())
assert.NotEqual(t, "UNKNOWN", ty.String())
}
}