[Bast-commits] r9689 - in SQL-Abstract/1.x/trunk: lib/SQL/Abstract t

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Mon Sep 6 16:45:18 GMT 2010


Author: frew
Date: 2010-09-06 17:45:18 +0100 (Mon, 06 Sep 2010)
New Revision: 9689

Added:
   SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t
Modified:
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm
Log:
whitespace tests

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm	2010-09-06 16:32:44 UTC (rev 9688)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract/Tree.pm	2010-09-06 16:45:18 UTC (rev 9689)
@@ -252,12 +252,11 @@
    my ($self, $keyword, $depth) = @_;
 
    my $before = '';
-   my $after  = ' ';
    if (defined $self->indentmap->{lc $keyword}) {
       $before = $self->newline . $self->indent($depth + $self->indentmap->{lc $keyword});
    }
    $before = '' if $depth == 0 and lc $keyword eq 'select';
-   return [$before, $after];
+   return [$before, ' '];
 }
 
 sub indent { ($_[0]->indent_string||'') x ( ( $_[0]->indent_amount || 0 ) * $_[1] ) }

Copied: SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t (from rev 9688, SQL-Abstract/1.x/trunk/t/12format_keyword.t)
===================================================================
--- SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t	                        (rev 0)
+++ SQL-Abstract/1.x/trunk/t/13whitespace_keyword.t	2010-09-06 16:45:18 UTC (rev 9689)
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use Test::More;
+use SQL::Abstract::Tree;
+
+my $sqlat = SQL::Abstract::Tree->new({
+	newline => "\n",
+	indent_string => " ",
+	indent_amount => 1,
+	indentmap => {
+      select     => 0,
+      where      => 1,
+      from       => 2,
+      join       => 3,
+      on         => 4,
+      'group by' => 5,
+      'order by' => 6,
+	},
+});
+
+for ( keys %{$sqlat->indentmap}) {
+	my ($l, $r) = @{$sqlat->whitespace($_, 1)};
+	is($r, ' ', "right is a space for $_");
+	is($l, "\n " . ' ' x $sqlat->indentmap->{$_}, "left calculated correctly for $_" );
+}
+
+is($sqlat->whitespace('select', 0)->[0], '', 'Select gets no newline or indent for depth 0');
+
+done_testing;




More information about the Bast-commits mailing list