Skip to content

Commit 101084b

Browse files
dbczumarandialbrecht
authored andcommitted
More test cases
1 parent 6f72de1 commit 101084b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

sqlparse/keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def is_keyword(value):
8989
r'(EXPLODE|INLINE|PARSE_URL_TUPLE|POSEXPLODE|STACK)\b',
9090
tokens.Keyword),
9191
(r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
92-
(r'(NOT\s)?(LIKE|ILIKE)\b', tokens.Operator.Comparison),
92+
(r'(NOT\s+)?(LIKE|ILIKE)\b', tokens.Operator.Comparison),
9393
(r'[0-9_A-ZÀ-Ü][_$#\w]*', is_keyword),
9494
(r'[;:()\[\],\.]', tokens.Punctuation),
9595
(r'[<>=~!]+', tokens.Operator.Comparison),

tests/test_grouping.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ def test_comparison_with_parenthesis():
472472
assert comp.right.ttype is T.Number.Integer
473473

474474

475-
@pytest.mark.parametrize('operator', ['LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE'])
475+
@pytest.mark.parametrize('operator', (
476+
'LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE',
477+
))
476478
def test_comparison_with_strings(operator):
477479
# issue148
478480
p = sqlparse.parse("foo {0} 'bar'".format(operator))[0]

tests/test_tokenize.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ def test_parse_order_by():
204204
assert p.tokens[0].ttype is T.Keyword
205205

206206

207+
@pytest.mark.parametrize('s', (
208+
"LIKE", "ILIKE", "NOT LIKE", "NOT ILIKE",
209+
"NOT LIKE", "NOT ILIKE",
210+
))
211+
def test_like_and_ilike_parsed_as_comparisons(s):
212+
p = sqlparse.parse(s)[0]
213+
assert len(p.tokens) == 1
214+
assert p.tokens[0].ttype == T.Operator.Comparison
215+
216+
217+
@pytest.mark.parametrize('s', (
218+
"LIKEaaa", "bILIKE", "aaILIKEbb", "NOTLIKE", "NOTILIKE",
219+
))
220+
def test_near_like_and_ilike_parsed_appropriately(s):
221+
p = sqlparse.parse(s)[0]
222+
assert len(p.tokens) == 1
223+
assert isinstance(p.tokens[0], sql.Identifier)
224+
225+
207226
@pytest.mark.parametrize('s', (
208227
'AT TIME ZONE \'UTC\'',
209228
))

0 commit comments

Comments
 (0)