sub _binary_op_keywords { @binary_op_keywords }
my %indents = (
- select => 0,
- where => 1,
- from => 1,
+ select => 0,
+ where => 1,
+ from => 1,
+ join => 1,
+ on => 2,
+ 'group by' => 1,
);
my %profiles = (
indent_amount => 2,
newline => "<br />\n",
colormap => {
- select => ['<span class="select">', '</span>'],
- where => ['<span class="where">', '</span>'],
- from => ['<span class="from">', '</span>'],
+ select => ['<span class="select">' , '</span>'],
+ where => ['<span class="where">' , '</span>'],
+ from => ['<span class="from">' , '</span>'],
+ join => ['<span class="join">' , '</span>'],
+ on => ['<span class="on">' , '</span>'],
+ 'group by' => ['<span class="group-by">', '</span>'],
},
indentmap => { %indents },
},
'simple statement with parens in where formatted correctly'
);
}
+
+ {
+ my $sql = "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]";
+ my $expected_sql =
+ "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] ";
+
+ is($sqlat->format($sql), $expected_sql,
+ 'real life statement 1 formatted correctly'
+ );
+ }
done_testing;
};
'simple statement with parens in where formatted correctly'
);
}
+
+ {
+ my $sql = "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]";
+ my $expected_sql =
+ "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] \n".
+ " FROM [users_roles] [me] \n" .
+ " JOIN [roles] [role] \n" .
+ " ON [role].[id] = [me].[role_id] \n" .
+ " JOIN [roles_permissions] [role_permissions] \n" .
+ " ON [role_permissions].[role_id] = [role].[id] \n" .
+ " JOIN [permissions] [permission] \n" .
+ " ON [permission].[id] = [role_permissions].[permission_id] \n" .
+ " JOIN [permissionscreens] [permission_screens] \n" .
+ " ON [permission_screens].[permission_id] = [permission].[id] \n" .
+ " JOIN [screens] [screen] \n" .
+ " ON [screen].[id] = [permission_screens].[screen_id] \n" .
+ " WHERE ([me].[user_id] = ?) \n" .
+ " GROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] ";
+
+ my $gotten = $sqlat->format($sql);
+ is($gotten, $expected_sql, 'real life statement 1 formatted correctly');
+ }
done_testing;
};
'simple statement with parens in where formatted correctly'
);
}
+
+ {
+ my $sql = "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]";
+ my $expected_sql =
+ qq{<span class="select">SELECT</span> [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] <br />\n}.
+ qq{ <span class="from">FROM</span> [users_roles] [me] <br />\n}.
+ qq{ <span class="join">JOIN</span> [roles] [role] <br />\n}.
+ qq{ <span class="on">ON</span> [role].[id] = [me].[role_id] <br />\n}.
+ qq{ <span class="join">JOIN</span> [roles_permissions] [role_permissions] <br />\n}.
+ qq{ <span class="on">ON</span> [role_permissions].[role_id] = [role].[id] <br />\n}.
+ qq{ <span class="join">JOIN</span> [permissions] [permission] <br />\n}.
+ qq{ <span class="on">ON</span> [permission].[id] = [role_permissions].[permission_id] <br />\n}.
+ qq{ <span class="join">JOIN</span> [permissionscreens] [permission_screens] <br />\n}.
+ qq{ <span class="on">ON</span> [permission_screens].[permission_id] = [permission].[id] <br />\n}.
+ qq{ <span class="join">JOIN</span> [screens] [screen] <br />\n}.
+ qq{ <span class="on">ON</span> [screen].[id] = [permission_screens].[screen_id] <br />\n}.
+ qq{ <span class="where">WHERE</span> ([me].[user_id] = ?) <br />\n}.
+ qq{ <span class="group-by">GROUP BY</span> [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] };
+
+ my $gotten = $sqlat->format($sql);
+ is($gotten, $expected_sql, 'real life statement 1 formatted correctly');
+ }
done_testing;
};
'simple statement with parens in where formatted correctly'
);
}
+
+ {
+ my $sql = "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]";
+ my $expected_sql =
+ "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] \r\n".
+ "\tFROM [users_roles] [me] \r\n" .
+ "\tJOIN [roles] [role] \r\n" .
+ "\t\tON [role].[id] = [me].[role_id] \r\n" .
+ "\tJOIN [roles_permissions] [role_permissions] \r\n" .
+ "\t\tON [role_permissions].[role_id] = [role].[id] \r\n" .
+ "\tJOIN [permissions] [permission] \r\n" .
+ "\t\tON [permission].[id] = [role_permissions].[permission_id] \r\n" .
+ "\tJOIN [permissionscreens] [permission_screens] \r\n" .
+ "\t\tON [permission_screens].[permission_id] = [permission].[id] \r\n" .
+ "\tJOIN [screens] [screen] \r\n" .
+ "\t\tON [screen].[id] = [permission_screens].[screen_id] \r\n" .
+ "\tWHERE ([me].[user_id] = ?) \r\n" .
+ "\tGROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] ";
+
+ my $gotten = $sqlat->format($sql);
+ is($gotten, $expected_sql, 'real life statement 1 formatted correctly');
+ }
done_testing;
};
done_testing;
# stuff we want:
# Max Width
-# Color coding (html)