[Bast-commits] r9676 - in SQL-Abstract/1.x/branches/sqla-tree: lib/SQL/Abstract t

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Sat Sep 4 01:12:46 GMT 2010


Author: frew
Date: 2010-09-04 02:12:46 +0100 (Sat, 04 Sep 2010)
New Revision: 9676

Modified:
   SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
   SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t
Log:
tests and slightly better profiles

Modified: SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm	2010-09-03 03:19:12 UTC (rev 9675)
+++ SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm	2010-09-04 01:12:46 UTC (rev 9676)
@@ -5,7 +5,6 @@
 use Carp;
 
 
-use Term::ANSIColor 'color';
 use base 'Class::Accessor::Grouped';
 
 __PACKAGE__->mk_group_accessors( simple => $_ ) for qw(
@@ -83,13 +82,20 @@
       indent_string => ' ',
       indent_amount => 2,
       newline       => "\n",
-      colormap      => {
-         select => [color('red'), color('reset')],
-         where  => [color('green'), color('reset')],
-         from   => [color('cyan'), color('reset')],
+      colormap      => {},
+      indentmap     => {
+         select => 0,
+         where  => 1,
+         from   => 1,
       },
-      indentmap => {
-         select     => 0,
+   },
+   console_monochrome => {
+      indent_string => ' ',
+      indent_amount => 2,
+      newline       => "\n",
+      colormap      => {},
+      indentmap     => {
+         select => 0,
          where  => 1,
          from   => 1,
       },
@@ -100,6 +106,15 @@
    },
 );
 
+eval {
+   require Term::ANSIColor;
+   $profiles{console}->{colormap} = {
+      select => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')],
+      where  => [Term::ANSIColor::color('green'), Term::ANSIColor::color('reset')],
+      from   => [Term::ANSIColor::color('cyan'), Term::ANSIColor::color('reset')],
+   };
+};
+
 sub new {
    my ($class, $args) = @_;
 
@@ -270,3 +285,15 @@
 
 1;
 
+=pod
+
+=head1 SYNOPSIS
+
+ my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' });
+
+ print $sqla_tree->format('SELECT * FROM foo WHERE foo.a > 2');
+
+ # SELECT *
+ #   FROM foo
+ #   WHERE foo.a > 2
+

Modified: SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t	2010-09-03 03:19:12 UTC (rev 9675)
+++ SQL-Abstract/1.x/branches/sqla-tree/t/11unparse.t	2010-09-04 01:12:46 UTC (rev 9676)
@@ -1,31 +1,52 @@
 use strict;
 use warnings;
 
+use Test::More;
 use SQL::Abstract::Tree;
 
-my $sqlat = SQL::Abstract::Tree->new({});
+my $sqlat = SQL::Abstract::Tree->new({
+   profile => 'console_monochrome',
+});
 
 {
    my $sql = "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'";
-
-   print "$sql\n";
-   print $sqlat->format($sql) . "\n";
+   my $expected_sql =
+      qq{SELECT a, b, c \n} .
+      qq{  FROM foo \n} .
+      qq{  WHERE foo.a = 1 AND foo.b LIKE 'station' };
+   is($sqlat->format($sql), $expected_sql,
+      'simple statement formatted correctly'
+   );
 }
 
 {
    my $sql = "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'";
+   my $expected_sql =
+      qq{SELECT * \n} .
+      qq{  FROM (\n} .
+      qq{    SELECT * \n} .
+      qq{      FROM foobar \n} .
+      qq{  ) \n} .
+      qq{  WHERE foo.a = 1 AND foo.b LIKE 'station' };
 
-   print "$sql\n";
-   print $sqlat->format($sql) . "\n";
+   is($sqlat->format($sql), $expected_sql,
+      'subquery statement formatted correctly'
+   );
 }
 
 {
    my $sql = "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'";
+   my $expected_sql =
+      qq{SELECT * \n} .
+      qq{  FROM lolz \n} .
+      qq{  WHERE (foo.a = 1) AND foo.b LIKE 'station' };
 
-   print "$sql\n";
-   print $sqlat->format($sql) . "\n";
+   is($sqlat->format($sql), $expected_sql,
+      'simple statement with parens in where formatted correctly'
+   );
 }
 
+done_testing;
 # stuff we want:
 #    Nested indentation
 #    Max Width




More information about the Bast-commits mailing list