(no commit message)
[scpubgit/Q-Branch.git] / t / 06order_by.t
CommitLineData
f5aab26e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Test::More;
6
7use SQL::Abstract;
8
96449e8e 9use FindBin;
10use lib "$FindBin::Bin";
11use TestSqlAbstract;
12
f5aab26e 13my @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
52my $sql = SQL::Abstract->new;
53my $sqlq = SQL::Abstract->new({quote_char => '`'});
54
55plan tests => (scalar(@cases) * 2);
56
57for my $case( @cases){
58 is($sql->_order_by($case->{given}), $case->{expects});
59 is($sqlq->_order_by($case->{given}), $case->{expects_quoted});
60}