Commit | Line | Data |
f5aab26e |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Test::More; |
6 | |
7 | use SQL::Abstract; |
8 | |
96449e8e |
9 | use FindBin; |
10 | use lib "$FindBin::Bin"; |
11 | use TestSqlAbstract; |
12 | |
f5aab26e |
13 | my @cases = |
14 | ( |
15 | { |
16 | given => \'colA DESC', |
17 | expects => ' ORDER BY colA DESC', |
18 | expects_quoted => ' ORDER BY colA DESC', |
19 | }, |
20 | { |
21 | given => 'colA', |
22 | expects => ' ORDER BY colA', |
23 | expects_quoted => ' ORDER BY `colA`', |
24 | }, |
25 | { |
26 | given => [qw/colA colB/], |
27 | expects => ' ORDER BY colA, colB', |
28 | expects_quoted => ' ORDER BY `colA`, `colB`', |
29 | }, |
30 | { |
31 | given => {-asc => 'colA'}, |
32 | expects => ' ORDER BY colA ASC', |
33 | expects_quoted => ' ORDER BY `colA` ASC', |
34 | }, |
35 | { |
36 | given => {-desc => 'colB'}, |
37 | expects => ' ORDER BY colB DESC', |
38 | expects_quoted => ' ORDER BY `colB` DESC', |
39 | }, |
40 | { |
41 | given => [{-asc => 'colA'}, {-desc => 'colB'}], |
42 | expects => ' ORDER BY colA ASC, colB DESC', |
43 | expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC', |
44 | }, |
1cfa1db3 |
45 | { |
46 | given => ['colA', {-desc => 'colB'}], |
47 | expects => ' ORDER BY colA, colB DESC', |
48 | expects_quoted => ' ORDER BY `colA`, `colB` DESC', |
49 | }, |
f5aab26e |
50 | ); |
51 | |
52 | my $sql = SQL::Abstract->new; |
53 | my $sqlq = SQL::Abstract->new({quote_char => '`'}); |
54 | |
55 | plan tests => (scalar(@cases) * 2); |
56 | |
57 | for my $case( @cases){ |
58 | is($sql->_order_by($case->{given}), $case->{expects}); |
59 | is($sqlq->_order_by($case->{given}), $case->{expects_quoted}); |
60 | } |