Mid-refactor: Convert from array refs to hashrefs for storing the AST in
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 001_basic.t
CommitLineData
a0185af2 1use strict;
2use warnings;
3
7a56723e 4use Test::More tests => 8;
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
7a56723e 12is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
a0185af2 13 "Simple name generator";
14
7a56723e 15is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 16 "me.*",
17 "Simple name generator";
18
19$sqla->quote_chars(['`']);
20
7a56723e 21is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 22 "`me`.*",
23 "Simple name generator";
24
25$sqla->disable_quoting;
26
c314b35d 27is $sqla->dispatch(
7a56723e 28 { -type => 'false' }
44cfd1f6 29), "0 = 1", "false value";
30
31is $sqla->dispatch(
7a56723e 32 { -type => 'true' }
44cfd1f6 33), "1 = 1", "true value";
34
35is $sqla->dispatch(
7a56723e 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 }
a0185af2 43), "me.id, me.foo.bar, bar",
44 "List generator";
4769c837 45
c314b35d 46is $sqla->dispatch(
7a56723e 47 { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" }
4769c837 48), "me.id AS foobar",
49 "Alias generator";
50
d2582f0f 51