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] ) }
--- /dev/null
+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;