from pugsql import lexer, context from unittest import TestCase ctx = context.Context('<literal>') def at(line, col): return context.Context(ctx.sqlfile, line, col) class LexTest(TestCase): def test_basic(self): l1 = lexer.Token('C', '-- :name username_for_id :1', at(1, 1)) l2 = lexer.Token( 'Q', 'select username from users where user_id = :user_id', at(2, 1)) self.assertEqual( [l1, l2], lexer.lex(open('tests/sql/basic.sql', 'r').read(), ctx)) def test_leading_comment_whitespace(self): l1 = lexer.Token('C', '-- :name username_for_id :1', at(1, 4)) l2 = lexer.Token( 'Q', 'select username from users where user_id = :user_id', at(2, 1)) self.assertEqual( [l1, l2], lexer.lex( ' -- :name username_for_id :1\n' 'select username from users where user_id = :user_id', ctx))
def at(line, col): return context.Context(ctx.sqlfile, line, col)
def at(l, c): return context.Context(ctx.sqlfile, l, c)