-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer_test.go
49 lines (42 loc) · 897 Bytes
/
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
package pggoquery
import (
"testing"
)
func TestNextToken(t *testing.T) {
input := `!=+(){},; SELECT * FROM users WHERE age > 20`
tests := []struct {
expectedType TokenType
expectedLiteral string
}{
{BANG, "!"},
{ASSIGN, "="},
{PLUS, "+"},
{LPAREN, "("},
{RPAREN, ")"},
{LBRACE, "{"},
{RBRACE, "}"},
{COMMA, ","},
{SEMICOLON, ";"},
{KEYWORD, "SELECT"},
{ASTERISK, "*"},
{KEYWORD, "FROM"},
{IDENT, "users"},
{KEYWORD, "WHERE"},
{IDENT, "age"},
{GT, ">"},
{INT, "20"},
{EOF, ""},
}
l := NewLexer(input)
for i, tt := range tests {
tok := l.NextToken()
if tok.Type != tt.expectedType {
t.Fatalf("tests[%d] - tokentype wrong. expected=%q, got=%q",
i, tt.expectedType, tok.Type)
}
if tok.Literal != tt.expectedLiteral {
t.Fatalf("tests[%d] - literal wrong. expected=%q, got=%q",
i, tt.expectedLiteral, tok.Literal)
}
}
}