one more test and some simple docs
[dbsrgits/SQL-Abstract.git] / t / 06order_by.t
CommitLineData
f5aab26e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use Test::More;
6
7use SQL::Abstract;
8
9my @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 },
1cfa1db3 41 {
42 given => ['colA', {-desc => 'colB'}],
43 expects => ' ORDER BY colA, colB DESC',
44 expects_quoted => ' ORDER BY `colA`, `colB` DESC',
45 },
f5aab26e 46 );
47
48my $sql = SQL::Abstract->new;
49my $sqlq = SQL::Abstract->new({quote_char => '`'});
50
51plan tests => (scalar(@cases) * 2);
52
53for my $case( @cases){
54 is($sql->_order_by($case->{given}), $case->{expects});
55 is($sqlq->_order_by($case->{given}), $case->{expects_quoted});
56}