Commit | Line | Data |
a0185af2 |
1 | use strict; |
2 | use warnings; |
3 | |
8b398780 |
4 | use Test::More tests => 10; |
5bf8c024 |
5 | use Test::Differences; |
a0185af2 |
6 | |
7 | use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); |
924d940e |
8 | use_ok('SQL::Abstract::AST::v1') or BAIL_OUT( "$@" ); |
a0185af2 |
9 | |
14774be0 |
10 | my $sqla = SQL::Abstract->create(1); |
0bf8a8c4 |
11 | |
12 | # TODO: once MXMS supports %args, use that here |
627dcb62 |
13 | is $sqla->dispatch( { -type => 'identifier', elements => [qw/me id/] }), "me.id", |
14 | "Simple identifier generator"; |
a0185af2 |
15 | |
627dcb62 |
16 | is $sqla->dispatch( { -type => 'identifier', elements => ['*'] } ), |
8b398780 |
17 | "*", |
627dcb62 |
18 | "* identifier generator"; |
8b398780 |
19 | |
627dcb62 |
20 | is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}), |
4ee32f41 |
21 | "me.*", |
627dcb62 |
22 | "Simple identifier generator"; |
4ee32f41 |
23 | |
24 | $sqla->quote_chars(['`']); |
25 | |
627dcb62 |
26 | is $sqla->dispatch( { -type => 'identifier', elements => [qw/me */]}), |
4ee32f41 |
27 | "`me`.*", |
627dcb62 |
28 | "Simple identifier generator"; |
4ee32f41 |
29 | |
30 | $sqla->disable_quoting; |
31 | |
c314b35d |
32 | is $sqla->dispatch( |
7a56723e |
33 | { -type => 'false' } |
44cfd1f6 |
34 | ), "0 = 1", "false value"; |
35 | |
36 | is $sqla->dispatch( |
7a56723e |
37 | { -type => 'true' } |
44cfd1f6 |
38 | ), "1 = 1", "true value"; |
39 | |
40 | is $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 |
51 | is $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 | |