Fix incorrect comparison of malformed lists
[scpubgit/Q-Branch.git] / t / 14roundtrippin.t
CommitLineData
ea5d73f1 1#!/usr/bin/env perl
2
3use Test::More;
4use SQL::Abstract::Test import => ['is_same_sql'];
5use SQL::Abstract::Tree;
6
7my $sqlat = SQL::Abstract::Tree->new;
8
9my @sql = (
efc991a0 10 "INSERT INTO artist DEFAULT VALUES",
11 "INSERT INTO artist VALUES ()",
12 "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'",
c4d7cfcf 13 "SELECT COUNT( * ) FROM foo",
14 "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a = 1 and foo.b LIKE 'station'",
efc991a0 15 "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'",
16 "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]",
af75bd59 17 "SELECT * FROM foo WHERE NOT EXISTS (SELECT bar FROM baz)",
ea5d73f1 18);
19
20for (@sql) {
c4d7cfcf 21 # Needs whitespace preservation in the AST to work, pending
22 #local $SQL::Abstract::Test::mysql_functions = 1;
23 is_same_sql ($sqlat->format($_), $_, sprintf 'roundtrip works (%s...)', substr $_, 0, 20);
ea5d73f1 24}
25
c4d7cfcf 26# delete this test when mysql_functions gets implemented
27my $sql = 'SELECT COUNT( * ) FROM foo';
28is($sqlat->format($sql), $sql, 'Roundtripping to mysql-compatible paren. syntax');
ea5d73f1 29
30done_testing;