Refactor to use a (hopefully) clearer dispatch table method
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 001_basic.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 9;
5 use Test::Differences;
6
7 use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
8
9 my $sqla = SQL::Abstract->create(1);
10
11 # TODO: once MXMS supports %args, use that here
12 is $sqla->dispatch( [ -name => qw/me id/]), "me.id",
13   "Simple name generator";
14
15 is $sqla->dispatch(
16   [ '-false' ]
17 ), "0 = 1", "false value";
18
19 is $sqla->dispatch(
20   [ '-true' ]
21 ), "1 = 1", "true value";
22
23 is $sqla->dispatch(
24   [ -list => 
25     [ -name => qw/me id/],
26     [ -name => qw/me foo bar/],
27     [ -name => qw/bar/]
28   ] 
29 ), "me.id, me.foo.bar, bar",
30   "List generator";
31
32 is $sqla->dispatch(
33   [ -alias => [ -name => qw/me id/], "foobar", ] 
34 ), "me.id AS foobar",
35   "Alias generator";
36
37 is $sqla->dispatch(
38   [ -order_by => [ -name => qw/me date/ ] ]
39 ), "ORDER BY me.date",
40    "order by";
41
42 is $sqla->dispatch(
43   [ -order_by => 
44     [ -name => qw/me date/ ],
45     [ -name => qw/me foobar/ ],
46   ]
47 ), "ORDER BY me.date, me.foobar",
48    "order by";
49
50 is $sqla->dispatch(
51   [ -order_by => [ -desc => [ -name => qw/me date/ ] ] ]
52 ), "ORDER BY me.date DESC",
53    "order by desc";
54
55