X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F42toplimit.t;h=15df15679bb912eb6f5aa638ad54f9227ec710dd;hb=65c2b042016f9bd215b8159586da02f9457ebf96;hp=aefbc0c17cc203711c0fd973f9bcf972829ed644;hpb=fd4cb60a0c582000de4beef5ba7a519fd531e168;p=dbsrgits%2FDBIx-Class.git diff --git a/t/42toplimit.t b/t/42toplimit.t index aefbc0c..15df156 100644 --- a/t/42toplimit.t +++ b/t/42toplimit.t @@ -1,45 +1,45 @@ -use strict; -use warnings; - -use Test::More; -use DBIx::Class::Storage::DBI; -use lib qw(t/lib); -use DBICTest; # do not remove even though it is not used -use DBIC::SqlMakerTest; - -plan tests => 8; - -my $sa = new DBIx::Class::SQLAHacks; -$sa->limit_dialect( 'Top' ); - -sub test_order { - my $args = shift; - my $order_by = $args->{order_by}; - my $expected_sql_order = $args->{expected_sql_order}; - - my $query = $sa->select( 'foo', [qw{bar baz}], undef, { - order_by => $order_by, - }, 1, 3 - ); - is_same_sql( - $query, - "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM foo ORDER BY $expected_sql_order->[0] ) AS foo ORDER BY $expected_sql_order->[1] ) AS bar ORDER BY $expected_sql_order->[0]", - ); -} - - test_order({ order_by => \'foo DESC' , expected_sql_order => [ 'foo DESC', 'foo ASC' ] }); - test_order({ order_by => 'foo' , expected_sql_order => [ 'foo ASC', 'foo DESC'] }); - test_order({ order_by => [ qw{ foo bar} ], expected_sql_order => [ 'foo ASC,bar ASC', 'foo DESC, bar DESC']}); - test_order({ order_by => { -asc => 'foo' }, expected_sql_order => [ 'foo ASC', 'foo DESC' ] }); - test_order({ order_by => { -desc => 'foo' }, expected_sql_order => [ 'foo DESC', 'foo ASC' ] }); - - test_order({ order_by => ['foo', { -desc => 'bar' } ], expected_sql_order => [ 'foo ASC, bar DESC', 'foo DESC, bar ASC'] }); - test_order({ order_by => {-asc => [qw{ foo bar }] }, expected_sql_order => ['foo ASC, bar ASC', 'foo DESC, bar DESC' ] }); - test_order({ order_by => - [ - { -asc => 'foo' }, - { -desc => [qw{bar}] }, - { -asc => [qw{baz frew}]}, - ], - expected_sql_order => ['foo ASC, bar DESC, baz ASC, frew ASC', 'foo DESC, bar ASC, baz DESC, frew DESC'] - }); +use strict; +use warnings; + +use Test::More; +use DBIx::Class::Storage::DBI; +use lib qw(t/lib); +use DBICTest; # do not remove even though it is not used +use DBIC::SqlMakerTest; + +plan tests => 8; + +my $sa = new DBIx::Class::SQLAHacks; +$sa->limit_dialect( 'Top' ); + +sub test_order { + my $args = shift; + my $order_by = $args->{order_by}; + my $expected_sql_order = $args->{expected_sql_order}; + + my $query = $sa->select( 'foo', [qw{bar baz}], undef, { + order_by => $order_by, + }, 1, 3 + ); + is_same_sql( + $query, + "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM foo ORDER BY $expected_sql_order->[0] ) AS foo ORDER BY $expected_sql_order->[1] ) AS bar ORDER BY $expected_sql_order->[0]", + ); +} + + test_order({ order_by => \'foo DESC' , expected_sql_order => [ 'foo DESC', 'foo ASC' ] }); + test_order({ order_by => 'foo' , expected_sql_order => [ 'foo ASC', 'foo DESC'] }); + test_order({ order_by => [ qw{ foo bar} ], expected_sql_order => [ 'foo ASC,bar ASC', 'foo DESC, bar DESC']}); + test_order({ order_by => { -asc => 'foo' }, expected_sql_order => [ 'foo ASC', 'foo DESC' ] }); + test_order({ order_by => { -desc => 'foo' }, expected_sql_order => [ 'foo DESC', 'foo ASC' ] }); + + test_order({ order_by => ['foo', { -desc => 'bar' } ], expected_sql_order => [ 'foo ASC, bar DESC', 'foo DESC, bar ASC'] }); + test_order({ order_by => {-asc => [qw{ foo bar }] }, expected_sql_order => ['foo ASC, bar ASC', 'foo DESC, bar DESC' ] }); + test_order({ order_by => + [ + { -asc => 'foo' }, + { -desc => [qw{bar}] }, + { -asc => [qw{baz frew}]}, + ], + expected_sql_order => ['foo ASC, bar DESC, baz ASC, frew ASC', 'foo DESC, bar ASC, baz DESC, frew DESC'] + });