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