10 use SQL::Abstract::Test import => ['is_same_sql_bind'];
14 given => \'colA DESC',
15 expects => ' ORDER BY colA DESC',
16 expects_quoted => ' ORDER BY colA DESC',
20 expects => ' ORDER BY colA',
21 expects_quoted => ' ORDER BY `colA`',
23 { # it may look odd, but this is the desired behaviour (mst)
25 expects => ' ORDER BY colA DESC',
26 expects_quoted => ' ORDER BY `colA DESC`',
29 given => [qw/colA colB/],
30 expects => ' ORDER BY colA, colB',
31 expects_quoted => ' ORDER BY `colA`, `colB`',
33 { # it may look odd, but this is the desired behaviour (mst)
34 given => ['colA ASC', 'colB DESC'],
35 expects => ' ORDER BY colA ASC, colB DESC',
36 expects_quoted => ' ORDER BY `colA ASC`, `colB DESC`',
39 given => {-asc => 'colA'},
40 expects => ' ORDER BY colA ASC',
41 expects_quoted => ' ORDER BY `colA` ASC',
44 given => {-desc => 'colB'},
45 expects => ' ORDER BY colB DESC',
46 expects_quoted => ' ORDER BY `colB` DESC',
49 given => [{-asc => 'colA'}, {-desc => 'colB'}],
50 expects => ' ORDER BY colA ASC, colB DESC',
51 expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC',
54 given => ['colA', {-desc => 'colB'}],
55 expects => ' ORDER BY colA, colB DESC',
56 expects_quoted => ' ORDER BY `colA`, `colB` DESC',
65 given => [{-desc => [ qw/colA colB/ ] }],
66 expects => ' ORDER BY colA DESC, colB DESC',
67 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC',
70 given => [{-desc => [ qw/colA colB/ ] }, {-asc => 'colC'}],
71 expects => ' ORDER BY colA DESC, colB DESC, colC ASC',
72 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC',
75 given => [{-desc => [ qw/colA colB/ ] }, {-asc => [ qw/colC colD/ ] }],
76 expects => ' ORDER BY colA DESC, colB DESC, colC ASC, colD ASC',
77 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC, `colD` ASC',
80 given => [{-desc => [ qw/colA colB/ ] }, {-desc => 'colC' }],
81 expects => ' ORDER BY colA DESC, colB DESC, colC DESC',
82 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` DESC',
85 given => [{ -asc => 'colA' }, { -desc => [qw/colB/] }, { -asc => [qw/colC colD/] }],
86 expects => ' ORDER BY colA ASC, colB DESC, colC ASC, colD ASC',
87 expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC, `colC` ASC, `colD` ASC',
90 given => { -desc => \['colA LIKE ?', 'test'] },
91 expects => ' ORDER BY colA LIKE ? DESC',
92 expects_quoted => ' ORDER BY colA LIKE ? DESC',
96 given => [ { -asc => \['colA'] }, { -desc => \['colB LIKE ?', 'test'] }, { -asc => \['colC LIKE ?', 'tost'] }],
97 expects => ' ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
98 expects_quoted => ' ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
99 bind => [qw/test tost/],
104 plan tests => (scalar(@cases) * 2) + 2;
106 my $sql = SQL::Abstract->new;
107 my $sqlq = SQL::Abstract->new({quote_char => '`'});
109 for my $case( @cases) {
112 ($stat, @bind) = $sql->_order_by($case->{given});
120 ($stat, @bind) = $sqlq->_order_by($case->{given});
124 $case->{expects_quoted},
130 sub { $sql->_order_by({-desc => 'colA', -asc => 'colB' }) },
131 qr/hash passed .+ must have exactly one key/,
132 'Undeterministic order exception',
136 sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) },
137 qr/hash passed .+ must have exactly one key/,
138 'Undeterministic order exception',