def test_parse_call(): assert parse('test()', a.Call) == a.Call('test', []) assert parse('test(1, bar)', a.Call) == a.Call( 'test', [a.Integer('1'), a.Name('bar')]) assert parse('test(1, bar(2, 3))', a.Call) == a.Call( 'test', [ a.Integer('1'), a.Call('bar', [a.Integer('2'), a.Integer('3')]), ])
def test_parse_from_clause(): assert parse('from test', a.FromClause) == a.FromClause([a.TableRef('test')]) assert parse('from public.test, public.test as foo', a.FromClause) == a.FromClause([ a.TableRef('test', 'public'), a.TableRef('test', 'public', 'foo'), ])
def test_parse_trim(): assert parse("trim(from 'foo')", p.special_calls) == a.Call( 'trim', [a.String("'both'"), a.String("' '"), a.String("'foo'")]) assert parse("trim(leading from 'foo')", p.special_calls) == a.Call( 'trim', [a.String("'leading'"), a.String("' '"), a.String("'foo'")]) assert parse("trim('xyz' from 'foo')", p.special_calls) == a.Call( 'trim', [a.String("'both'"), a.String("'xyz'"), a.String("'foo'")])
def test_parse_exaples(query, ast): assert parse(query) == ast
def test_parse_quoted_strings(): assert parse( r"'{''foo'':''bar'', ''hello'': ''world''}'", a.String) == a.String(r"'{''foo'':''bar'', ''hello'': ''world''}'")
def test_parse_call_set_function(): assert parse('min(foo)', a.CallSetFunction) == a.CallSetFunction( 'min', [a.Name('foo')])
def test_parse_table_ref(): assert parse('test', a.TableRef) == a.TableRef('test') assert parse('public.test', a.TableRef) == a.TableRef('test', 'public') assert parse('public.test as foo', a.TableRef) == a.TableRef('test', 'public', 'foo')