849a9824d55c5d6c1ad5e88267da6298addfbc7a
[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 use_ok('SQL::Abstract::AST::v1') or BAIL_OUT( "$@" );
9
10 my $sqla = SQL::Abstract->create(1);
11
12 # TODO: once MXMS supports %args, use that here
13 is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
14   "Simple name generator";
15
16 is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
17    "me.*",
18    "Simple name generator";
19
20 $sqla->quote_chars(['`']);
21
22 is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
23    "`me`.*",
24    "Simple name generator";
25
26 $sqla->disable_quoting;
27
28 is $sqla->dispatch(
29   { -type => 'false' }
30 ), "0 = 1", "false value";
31
32 is $sqla->dispatch(
33   { -type => 'true' }
34 ), "1 = 1", "true value";
35
36 is $sqla->dispatch(
37   { -type => 'list',
38     args => [
39       { -type => name => args => [qw/me id/] },
40       { -type => name => args => [qw/me foo bar/] },
41       { -type => name => args => [qw/bar/] }
42     ] 
43   }
44 ), "me.id, me.foo.bar, bar",
45   "List generator";
46
47 is $sqla->dispatch(
48   { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" } 
49 ), "me.id AS foobar",
50   "Alias generator";
51
52