From: Arthur Axel "fREW" Schmidt Date: Fri, 22 Oct 2010 04:12:18 +0000 (+0000) Subject: fix tree tests X-Git-Tag: v1.70~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=958f1ce453b1065f3c152a791611cc688a354d6e;p=dbsrgits%2FSQL-Abstract.git fix tree tests --- diff --git a/t/11unparse.t b/t/11unparse.t index 0b21339..e61416b 100644 --- a/t/11unparse.t +++ b/t/11unparse.t @@ -7,17 +7,696 @@ use SQL::Abstract::Tree; my $sqlat = SQL::Abstract::Tree->new; -cmp_deeply($sqlat->parse("SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"), [ [ [ "SELECT", [ [ "LITERAL", [ "a, b, c" ] ] ] ], [ "FROM", [ [ "LITERAL", [ "foo" ] ] ] ] ], [ "WHERE", [ [ "AND", [ [ "=", [ [ "LITERAL", [ "foo.a" ] ], [ "LITERAL", [ 1 ] ] ] ], [ "LIKE", [ [ "LITERAL", [ "foo.b" ] ], [ "LITERAL", [ "'station'" ] ] ] ] ] ] ] ] ], 'simple statement parsed correctly'); +cmp_deeply($sqlat->parse("SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"), [ + [ + [ + "SELECT", + [ + [ + "LIST", + [ + [ + "LITERAL", + [ + "a" + ] + ], + [ + "LITERAL", + [ + "b" + ] + ], + [ + "LITERAL", + [ + "c" + ] + ] + ] + ] + ] + ], + [ + "FROM", + [ + [ + "LITERAL", + [ + "foo" + ] + ] + ] + ] + ], + [ + "WHERE", + [ + [ + "AND", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "foo.a" + ] + ], + [ + "LITERAL", + [ + 1 + ] + ] + ] + ], + [ + "LIKE", + [ + [ + "LITERAL", + [ + "foo.b" + ] + ], + [ + "LITERAL", + [ + "'station'" + ] + ] + ] + ] + ] + ] + ] + ] +], 'simple statement parsed correctly'); +cmp_deeply($sqlat->parse( "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"), [ + [ + [ + "SELECT", + [ + [ + "LITERAL", + [ + "*" + ] + ] + ] + ], + [ + "FROM", + [ + [ + "PAREN", + [ + [ + [ + "SELECT", + [ + [ + "LITERAL", + [ + "*" + ] + ] + ] + ], + [ + "FROM", + [ + [ + "LITERAL", + [ + "foobar" + ] + ] + ] + ] + ] + ] + ] + ] + ] + ], + [ + "WHERE", + [ + [ + "AND", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "foo.a" + ] + ], + [ + "LITERAL", + [ + 1 + ] + ] + ] + ], + [ + "LIKE", + [ + [ + "LITERAL", + [ + "foo.b" + ] + ], + [ + "LITERAL", + [ + "'station'" + ] + ] + ] + ] + ] + ] + ] + ] +], 'subquery statement parsed correctly'); -cmp_deeply($sqlat->parse( "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"), [ [ [ "SELECT", [ [ "LITERAL", [ "*" ] ] ] ], [ "FROM", [ [ "PAREN", [ [ [ "SELECT", [ [ "LITERAL", [ "*" ] ] ] ], [ "FROM", [ [ "LITERAL", [ "foobar" ] ] ] ] ] ] ] ] ] ], [ "WHERE", [ [ "AND", [ [ "=", [ [ "LITERAL", [ "foo.a" ] ], [ "LITERAL", [ 1 ] ] ] ], [ "LIKE", [ [ "LITERAL", [ "foo.b" ] ], [ "LITERAL", [ "'station'" ] ] ] ] ] ] ] ] ], 'subquery statement parsed correctly'); +cmp_deeply($sqlat->parse("SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'"), [ + [ + [ + "SELECT", + [ + [ + "LITERAL", + [ + "*" + ] + ] + ] + ], + [ + "FROM", + [ + [ + "LITERAL", + [ + "lolz" + ] + ] + ] + ] + ], + [ + "WHERE", + [ + [ + "AND", + [ + [ + "PAREN", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "foo.a" + ] + ], + [ + "LITERAL", + [ + 1 + ] + ] + ] + ] + ] + ], + [ + "LIKE", + [ + [ + "LITERAL", + [ + "foo.b" + ] + ], + [ + "LITERAL", + [ + "'station'" + ] + ] + ] + ] + ] + ] + ] + ] +], 'simple statement with parens in where parsed correctly'); -cmp_deeply($sqlat->parse("SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'"), [ [ [ "SELECT", [ [ "LITERAL", [ "*" ] ] ] ], [ "FROM", [ [ "LITERAL", [ "lolz" ] ] ] ] ], [ "WHERE", [ [ "AND", [ [ "PAREN", [ [ "=", [ [ "LITERAL", [ "foo.a" ] ], [ "LITERAL", [ 1 ] ] ] ] ] ], [ "LIKE", [ [ "LITERAL", [ "foo.b" ] ], [ "LITERAL", [ "'station'" ] ] ] ] ] ] ] ] ], 'simple statement with parens in where parsed correctly'); +cmp_deeply($sqlat->parse( "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] FROM [users_roles] [me] JOIN [roles] [role] ON [role].[id] = [me].[role_id] JOIN [roles_permissions] [role_permissions] ON [role_permissions].[role_id] = [role].[id] JOIN [permissions] [permission] ON [permission].[id] = [role_permissions].[permission_id] JOIN [permissionscreens] [permission_screens] ON [permission_screens].[permission_id] = [permission].[id] JOIN [screens] [screen] ON [screen].[id] = [permission_screens].[screen_id] WHERE ( [me].[user_id] = ? ) GROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]"), [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + [ + "SELECT", + [ + [ + "LIST", + [ + [ + "LITERAL", + [ + "[screen].[id]" + ] + ], + [ + "LITERAL", + [ + "[screen].[name]" + ] + ], + [ + "LITERAL", + [ + "[screen].[section_id]" + ] + ], + [ + "LITERAL", + [ + "[screen].[xtype]" + ] + ] + ] + ] + ] + ], + [ + "FROM", + [ + [ + [ + "LITERAL", + [ + "[users_roles]" + ] + ], + [ + "LITERAL", + [ + "[me]" + ] + ] + ] + ] + ] + ], + [ + "JOIN", + [ + [ + [ + "LITERAL", + [ + "[roles]" + ] + ], + [ + "LITERAL", + [ + "[role]" + ] + ] + ] + ] + ] + ], + [ + "ON", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[role].[id]" + ] + ], + [ + "LITERAL", + [ + "[me].[role_id]" + ] + ] + ] + ] + ] + ] + ], + [ + "JOIN", + [ + [ + [ + "LITERAL", + [ + "[roles_permissions]" + ] + ], + [ + "LITERAL", + [ + "[role_permissions]" + ] + ] + ] + ] + ] + ], + [ + "ON", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[role_permissions].[role_id]" + ] + ], + [ + "LITERAL", + [ + "[role].[id]" + ] + ] + ] + ] + ] + ] + ], + [ + "JOIN", + [ + [ + [ + "LITERAL", + [ + "[permissions]" + ] + ], + [ + "LITERAL", + [ + "[permission]" + ] + ] + ] + ] + ] + ], + [ + "ON", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[permission].[id]" + ] + ], + [ + "LITERAL", + [ + "[role_permissions].[permission_id]" + ] + ] + ] + ] + ] + ] + ], + [ + "JOIN", + [ + [ + [ + "LITERAL", + [ + "[permissionscreens]" + ] + ], + [ + "LITERAL", + [ + "[permission_screens]" + ] + ] + ] + ] + ] + ], + [ + "ON", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[permission_screens].[permission_id]" + ] + ], + [ + "LITERAL", + [ + "[permission].[id]" + ] + ] + ] + ] + ] + ] + ], + [ + "JOIN", + [ + [ + [ + "LITERAL", + [ + "[screens]" + ] + ], + [ + "LITERAL", + [ + "[screen]" + ] + ] + ] + ] + ] + ], + [ + "ON", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[screen].[id]" + ] + ], + [ + "LITERAL", + [ + "[permission_screens].[screen_id]" + ] + ] + ] + ] + ] + ] + ], + [ + "WHERE", + [ + [ + "PAREN", + [ + [ + "=", + [ + [ + "LITERAL", + [ + "[me].[user_id]" + ] + ], + [ + "PLACEHOLDER", + [ + "?" + ] + ] + ] + ] + ] + ] + ] + ] + ], + [ + "GROUP BY", + [ + [ + "LIST", + [ + [ + "LITERAL", + [ + "[screen].[id]" + ] + ], + [ + "LITERAL", + [ + "[screen].[name]" + ] + ], + [ + "LITERAL", + [ + "[screen].[section_id]" + ] + ], + [ + "LITERAL", + [ + "[screen].[xtype]" + ] + ] + ] + ] + ] + ] +], 'real life statement 1 parsed correctly'); -cmp_deeply($sqlat->parse( "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] FROM [users_roles] [me] JOIN [roles] [role] ON [role].[id] = [me].[role_id] JOIN [roles_permissions] [role_permissions] ON [role_permissions].[role_id] = [role].[id] JOIN [permissions] [permission] ON [permission].[id] = [role_permissions].[permission_id] JOIN [permissionscreens] [permission_screens] ON [permission_screens].[permission_id] = [permission].[id] JOIN [screens] [screen] ON [screen].[id] = [permission_screens].[screen_id] WHERE ( [me].[user_id] = ? ) GROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]"), [ [ [ [ [ [ [ [ [ [ [ [ [ [ "SELECT", [ [ "LITERAL", [ "[screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]" ] ] ] ], [ "FROM", [ [ "LITERAL", [ "[users_roles] [me]" ] ] ] ] ], [ "JOIN", [ [ "LITERAL", [ "[roles] [role]" ] ] ] ] ], [ "ON", [ [ "=", [ [ "LITERAL", [ "[role].[id]" ] ], [ "LITERAL", [ "[me].[role_id]" ] ] ] ] ] ] ], [ "JOIN", [ [ "LITERAL", [ "[roles_permissions] [role_permissions]" ] ] ] ] ], [ "ON", [ [ "=", [ [ "LITERAL", [ "[role_permissions].[role_id]" ] ], [ "LITERAL", [ "[role].[id]" ] ] ] ] ] ] ], [ "JOIN", [ [ "LITERAL", [ "[permissions] [permission]" ] ] ] ] ], [ "ON", [ [ "=", [ [ "LITERAL", [ "[permission].[id]" ] ], [ "LITERAL", [ "[role_permissions].[permission_id]" ] ] ] ] ] ] ], [ "JOIN", [ [ "LITERAL", [ "[permissionscreens] [permission_screens]" ] ] ] ] ], [ "ON", [ [ "=", [ [ "LITERAL", [ "[permission_screens].[permission_id]" ] ], [ "LITERAL", [ "[permission].[id]" ] ] ] ] ] ] ], [ "JOIN", [ [ "LITERAL", [ "[screens] [screen]" ] ] ] ] ], [ "ON", [ [ "=", [ [ "LITERAL", [ "[screen].[id]" ] ], [ "LITERAL", [ "[permission_screens].[screen_id]" ] ] ] ] ] ] ], [ "WHERE", [ [ "PAREN", [ [ "=", [ [ "LITERAL", [ "[me].[user_id]" ] ], [ "LITERAL", [ "?" ] ] ] ] ] ] ] ] ], [ "GROUP BY", [ [ "LITERAL", [ "[screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]" ] ] ] ] ], - 'real life statement 1 parsed correctly' -); - -cmp_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [ [ [ "SELECT", [ [ "LITERAL", [ "x", "y" ] ] ] ], [ "FROM", [ [ "LITERAL", [ "foo" ] ] ] ] ], [ "WHERE", [ [ "IN", [ "LITERAL", [ "?", "?", "?", "?" ] ] ] ] ] ], 'Lists parsed correctly'); +cmp_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [ + [ + [ + "SELECT", + [ + [ + "LIST", + [ + [ + "LITERAL", + [ + "x" + ] + ], + [ + "LITERAL", + [ + "y" + ] + ] + ] + ] + ] + ], + [ + "FROM", + [ + [ + "LITERAL", + [ + "foo" + ] + ] + ] + ] + ], + [ + "WHERE", + [ + [ + "IN", + [ + [ + "LITERAL", + [ + "x" + ] + ], + [ + "PAREN", + [ + [ + "LIST", + [ + [ + "PLACEHOLDER", + [ + "?" + ] + ], + [ + "PLACEHOLDER", + [ + "?" + ] + ], + [ + "PLACEHOLDER", + [ + "?" + ] + ], + [ + "PLACEHOLDER", + [ + "?" + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] +], 'Lists parsed correctly'); done_testing;