728d948a3d6bf62c01241a60a476368f6f4ac746
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 001_basic.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 8;
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( { -type => 'name', args => [qw/me id/] }), "me.id",
13   "Simple name generator";
14
15 is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
16    "me.*",
17    "Simple name generator";
18
19 $sqla->quote_chars(['`']);
20
21 is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
22    "`me`.*",
23    "Simple name generator";
24
25 $sqla->disable_quoting;
26
27 is $sqla->dispatch(
28   { -type => 'false' }
29 ), "0 = 1", "false value";
30
31 is $sqla->dispatch(
32   { -type => 'true' }
33 ), "1 = 1", "true value";
34
35 is $sqla->dispatch(
36   { -type => 'list',
37     args => [
38       { -type => name => args => [qw/me id/] },
39       { -type => name => args => [qw/me foo bar/] },
40       { -type => name => args => [qw/bar/] }
41     ] 
42   }
43 ), "me.id, me.foo.bar, bar",
44   "List generator";
45
46 is $sqla->dispatch(
47   { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" } 
48 ), "me.id AS foobar",
49   "Alias generator";
50
51