Repository navigation
Expand file tree
/
Copy pathlexer.spec.coffee
More file actions
65 lines (60 loc) · 1.69 KB
/
Copy pathlexer.spec.coffee
File metadata and controls
65 lines (60 loc) · 1.69 KB
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
lexer = require('../lib/lexer')
describe "SQL Lexer", ->
it "eats select queries", ->
tokens = lexer.tokenize("select * from my_table")
tokens.should.eql [
["SELECT", "select", 1]
["STAR", "*", 1]
["FROM", "from", 1]
["LITERAL", "my_table", 1]
["EOF", "", 1]
]
it "eats select queries with stars and multiplication", ->
tokens = lexer.tokenize("select * from my_table where foo = 1 * 2")
tokens.should.eql [
["SELECT", "select", 1]
["STAR", "*", 1]
["FROM", "from", 1]
["LITERAL", "my_table", 1]
["WHERE", "where", 1]
["LITERAL", "foo", 1]
["OPERATOR", "=", 1]
["NUMBER", "1", 1]
["MATH_MULTI", "*", 1]
["NUMBER", "2", 1]
["EOF", "", 1]
]
it "eats sub selects", ->
tokens = lexer.tokenize("select * from (select * from my_table) t")
tokens.should.eql [
["SELECT", "select", 1]
["STAR", "*", 1]
["FROM", "from", 1]
[ 'LEFT_PAREN', '(', 1 ]
[ 'SELECT', 'select', 1 ]
[ 'STAR', '*', 1 ]
[ 'FROM', 'from', 1 ]
[ 'LITERAL', 'my_table', 1 ]
[ 'RIGHT_PAREN', ')', 1 ]
["LITERAL", "t", 1]
["EOF", "", 1]
]
it "eats joins", ->
tokens = lexer.tokenize("select * from a join b on a.id = b.id")
tokens.should.eql [
["SELECT", "select", 1]
["STAR", "*", 1]
["FROM", "from", 1]
[ 'LITERAL', 'a', 1 ]
[ 'JOIN', 'join', 1 ]
[ 'LITERAL', 'b', 1 ]
[ 'ON', 'on', 1 ]
[ 'LITERAL', 'a', 1 ]
[ 'DOT', '.', 1 ]
[ 'LITERAL', 'id', 1 ]
[ 'OPERATOR', '=', 1 ]
[ 'LITERAL', 'b', 1 ]
[ 'DOT', '.', 1 ]
[ 'LITERAL', 'id', 1 ]
["EOF", "", 1]
]