Add Compat->AST tests for the complex test from compat/00new.t
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 001_basic.t
CommitLineData
a0185af2 1use strict;
2use warnings;
3
8b398780 4use Test::More tests => 10;
5bf8c024 5use Test::Differences;
a0185af2 6
7use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
924d940e 8use_ok('SQL::Abstract::AST::v1') or BAIL_OUT( "$@" );
a0185af2 9
14774be0 10my $sqla = SQL::Abstract->create(1);
0bf8a8c4 11
12# TODO: once MXMS supports %args, use that here
7a56723e 13is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
a0185af2 14 "Simple name generator";
15
8b398780 16is $sqla->dispatch( { -type => 'name', args => ['*'] } ),
17 "*",
18 "* name generator";
19
7a56723e 20is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 21 "me.*",
22 "Simple name generator";
23
24$sqla->quote_chars(['`']);
25
7a56723e 26is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 27 "`me`.*",
28 "Simple name generator";
29
30$sqla->disable_quoting;
31
c314b35d 32is $sqla->dispatch(
7a56723e 33 { -type => 'false' }
44cfd1f6 34), "0 = 1", "false value";
35
36is $sqla->dispatch(
7a56723e 37 { -type => 'true' }
44cfd1f6 38), "1 = 1", "true value";
39
40is $sqla->dispatch(
7a56723e 41 { -type => 'list',
42 args => [
43 { -type => name => args => [qw/me id/] },
44 { -type => name => args => [qw/me foo bar/] },
45 { -type => name => args => [qw/bar/] }
46 ]
47 }
a0185af2 48), "me.id, me.foo.bar, bar",
49 "List generator";
4769c837 50
c314b35d 51is $sqla->dispatch(
7a56723e 52 { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" }
4769c837 53), "me.id AS foobar",
54 "Alias generator";
55
d2582f0f 56