-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
SimpleSqlGrammarTest.groovy
36 lines (30 loc) · 1.54 KB
/
SimpleSqlGrammarTest.groovy
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
package liquibase.util.grammar
import spock.lang.Specification
import spock.lang.Unroll
class SimpleSqlGrammarTest extends Specification {
@Unroll
def test() {
when:
def grammar = new SimpleSqlGrammar(new ByteArrayInputStream(input.getBytes()))
def tokens = new ArrayList<String>()
Token token
while ((token = grammar.getNextToken()).kind != SimpleSqlGrammarConstants.EOF) {
tokens.add(token.toString())
}
then:
tokens == expected
where:
input | expected
"" | []
"sql goes here" | ["sql", " ", "goes", " ", "here"]
" odd spacing stuff " | [" ", "odd", " ", "spacing", " ", "stuff", " "]
"create table test" | ["create", " ", "table", " ", "test"]
"create table catalog.schema.test" | ["create", " ", "table", " ", "catalog.schema.test"]
"create table [test]" | ["create", " ", "table", " ", "[test]"]
"create table \"test\"" | ["create", " ", "table", " ", "\"test\""]
"create table /* comment here */ test" | ["create", " ", "table", " ", "/* comment here */", " ", "test"]
"insert 'a string'" | ["insert", " ", "'a string'"]
"invalid ' sql" | ["invalid", " ", "'", " ", "sql"]
"utf8-〠@chars works" | ["utf8", "-", "〠@chars", " ", "works"]
}
}