From: Arthur Axel "fREW" Schmidt Date: Mon, 6 Sep 2010 16:45:18 +0000 (+0000) Subject: whitespace tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b4e0e260fc40159f0e12b6e98b68ecdcb30b3ab1;p=scpubgit%2FQ-Branch.git whitespace tests --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 7870e48..0110fc5 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -252,12 +252,11 @@ sub whitespace { 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] ) } diff --git a/t/13whitespace_keyword.t b/t/13whitespace_keyword.t new file mode 100644 index 0000000..2d2319c --- /dev/null +++ b/t/13whitespace_keyword.t @@ -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;