X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F06order_by.t;h=2b3b13f59fee1433e41d619948fbad62f24ceab2;hb=36e3ea6ca294fa0c1a32cefa39ec23146498faf0;hp=25a4f32e7e7535d8f490518ece0b5a7721a2e625;hpb=a60d973aae9467a8afbccbde197423ec31e86bc8;p=dbsrgits%2FSQL-Abstract.git diff --git a/t/06order_by.t b/t/06order_by.t index 25a4f32..2b3b13f 100644 --- a/t/06order_by.t +++ b/t/06order_by.t @@ -104,10 +104,25 @@ my @cases = expects_quoted => ' ORDER BY colA, colB LIKE ? DESC, colC LIKE ?', bind => [qw/test tost/], }, + { + given => [ { -asc => 'colA', -nulls => 'first' }, { -desc => 'colB', -nulls => 'last' } ], + expects => ' ORDER BY colA NULLS FIRST, colB DESC NULLS LAST', + expects_quoted => ' ORDER BY `colA` NULLS FIRST, `colB` DESC NULLS LAST', + }, + { + given => [ { -asc => 'colA', -nulls => 'first' }, { -desc => 'colB', -nulls => 'last' } ], + expects => ' ORDER BY colA NULLS FIRST, colB DESC NULLS LAST', + expects_quoted => ' ORDER BY `colA` NULLS FIRST, `colB` DESC NULLS LAST', + }, + { + given => { -asc => [qw/colA colB/], -nulls => 'first' } , + expects => ' ORDER BY colA NULLS FIRST, colB NULLS FIRST', + expects_quoted => ' ORDER BY `colA` NULLS FIRST, `colB` NULLS FIRST', + }, ); -plan tests => (scalar(@cases) * 2) + 2; +plan tests => (scalar(@cases) * 2) + 4; my $sql = SQL::Abstract->new; my $sqlq = SQL::Abstract->new({quote_char => '`'}); @@ -134,12 +149,24 @@ for my $case( @cases) { throws_ok ( sub { $sql->_order_by({-desc => 'colA', -asc => 'colB' }) }, - qr/hash passed .+ must have exactly one key/, + qr/hash passed .+ must have exactly one of/, 'Undeterministic order exception', ); throws_ok ( sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) }, - qr/hash passed .+ must have exactly one key/, + qr/hash passed .+ must have exactly one of/, 'Undeterministic order exception', ); + +throws_ok( + sub { $sql->_order_by({-wibble => "fleem" }) }, + qr/invalid key in hash/, + 'Invalid order exception', +); + +throws_ok( + sub { $sql->_order_by({-nulls => "fleem" }) }, + qr/invalid value for -nulls/, + 'Invalid nulls exception', +);