bumped version but not $REVISION. small fix to order_by plus more tests. docs pending
[scpubgit/Q-Branch.git] / t / 06order_by.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6
7 use SQL::Abstract;
8
9 my @cases = 
10   (
11    {
12     given => \'colA DESC',
13     expects => ' ORDER BY colA DESC',
14     expects_quoted => ' ORDER BY colA DESC',
15    },
16    {
17     given => 'colA',
18     expects => ' ORDER BY colA',
19     expects_quoted => ' ORDER BY `colA`',
20    },
21    {
22     given => [qw/colA colB/],
23     expects => ' ORDER BY colA, colB',
24     expects_quoted => ' ORDER BY `colA`, `colB`',
25    },
26    {
27     given => {-asc => 'colA'},
28     expects => ' ORDER BY colA ASC',
29     expects_quoted => ' ORDER BY `colA` ASC',
30    },
31    {
32     given => {-desc => 'colB'},
33     expects => ' ORDER BY colB DESC',
34     expects_quoted => ' ORDER BY `colB` DESC',
35    },
36    {
37     given => [{-asc => 'colA'}, {-desc => 'colB'}],
38     expects => ' ORDER BY colA ASC, colB DESC',
39     expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC',
40    },
41   );
42
43 my $sql  = SQL::Abstract->new;
44 my $sqlq = SQL::Abstract->new({quote_char => '`'});
45
46 plan tests => (scalar(@cases) * 2);
47
48 for my $case( @cases){
49   is($sql->_order_by($case->{given}), $case->{expects});
50   is($sqlq->_order_by($case->{given}), $case->{expects_quoted});
51 }