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