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 | |
c461c25c |
9 | use SQL::Abstract::Test qw/is_same_sql_bind/; |
f5aab26e |
10 | my @cases = |
11 | ( |
12 | { |
13 | given => \'colA DESC', |
14 | expects => ' ORDER BY colA DESC', |
15 | expects_quoted => ' ORDER BY colA DESC', |
16 | }, |
17 | { |
18 | given => 'colA', |
19 | expects => ' ORDER BY colA', |
20 | expects_quoted => ' ORDER BY `colA`', |
21 | }, |
22 | { |
23 | given => [qw/colA colB/], |
24 | expects => ' ORDER BY colA, colB', |
25 | expects_quoted => ' ORDER BY `colA`, `colB`', |
26 | }, |
27 | { |
28 | given => {-asc => 'colA'}, |
29 | expects => ' ORDER BY colA ASC', |
30 | expects_quoted => ' ORDER BY `colA` ASC', |
31 | }, |
32 | { |
33 | given => {-desc => 'colB'}, |
34 | expects => ' ORDER BY colB DESC', |
35 | expects_quoted => ' ORDER BY `colB` DESC', |
36 | }, |
37 | { |
38 | given => [{-asc => 'colA'}, {-desc => 'colB'}], |
39 | expects => ' ORDER BY colA ASC, colB DESC', |
40 | expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC', |
41 | }, |
1cfa1db3 |
42 | { |
43 | given => ['colA', {-desc => 'colB'}], |
44 | expects => ' ORDER BY colA, colB DESC', |
45 | expects_quoted => ' ORDER BY `colA`, `colB` DESC', |
46 | }, |
f5aab26e |
47 | ); |
48 | |
49 | my $sql = SQL::Abstract->new; |
50 | my $sqlq = SQL::Abstract->new({quote_char => '`'}); |
51 | |
52 | plan tests => (scalar(@cases) * 2); |
53 | |
54 | for my $case( @cases){ |
55 | is($sql->_order_by($case->{given}), $case->{expects}); |
56 | is($sqlq->_order_by($case->{given}), $case->{expects_quoted}); |
57 | } |