Chage {-type => 'name', args => [] } to {-type => 'identifier', elements => [] }
[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
627dcb62 13is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }), "me.id",
14 "Simple identifier generator";
a0185af2 15
627dcb62 16is $sqla->dispatch( { -type => 'identifier', elements => ['*'] } ),
8b398780 17 "*",
627dcb62 18 "* identifier generator";
8b398780 19
627dcb62 20is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}),
4ee32f41 21 "me.*",
627dcb62 22 "Simple identifier generator";
4ee32f41 23
24$sqla->quote_chars(['`']);
25
627dcb62 26is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}),
4ee32f41 27 "`me`.*",
627dcb62 28 "Simple identifier generator";
4ee32f41 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 => [
627dcb62 43 { -type => identifier => elements => [qw/me id/] },
44 { -type => identifier => elements => [qw/me foo bar/] },
45 { -type => identifier => elements => [qw/bar/] }
7a56723e 46 ]
47 }
a0185af2 48), "me.id, me.foo.bar, bar",
49 "List generator";
4769c837 50
c314b35d 51is $sqla->dispatch(
627dcb62 52 { -type => 'alias', ident => { -type => identifier => elements => [qw/me id/]}, as => "foobar" }
4769c837 53), "me.id AS foobar",
54 "Alias generator";
55
d2582f0f 56