Commit | Line | Data |
ef0d6124 |
1 | use strict; |
2 | use warnings; |
3 | |
d4656fcf |
4 | use Test::More tests => 6; |
ef0d6124 |
5 | use Test::Exception; |
6 | |
d4656fcf |
7 | use FindBin; |
8 | use lib "$FindBin::Bin/lib"; |
9 | use Test::SQL::Abstract::Util qw/ |
10 | mk_name |
11 | mk_value |
12 | mk_alias |
13 | /; |
14 | |
ef0d6124 |
15 | use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); |
16 | |
17 | my $sqla = SQL::Abstract->create(1); |
18 | |
19 | throws_ok { |
20 | $sqla->dispatch( |
21 | { -type => 'expr', op => '==', |
22 | args => [ |
627dcb62 |
23 | { -type => 'identifier', elements => [qw/me id/] }, |
24 | { -type => 'alias', ident => { -type => 'identifier', elements => [qw/me id/] }, as => 'bar' } |
ef0d6124 |
25 | ] |
26 | } |
27 | ) |
28 | } qr/^'alias' is not a valid AST type in an expression/, "Error from invalid part in where"; |
29 | |
30 | throws_ok { |
31 | $sqla->dispatch( |
32 | { -type => 'expr', op => '~' } |
33 | ) |
747f7c21 |
34 | } qr/^'~' is not a valid operator in an expression/; |
35 | |
d4656fcf |
36 | { |
747f7c21 |
37 | local $TODO = "Work out how to get nice errors for these"; |
38 | |
39 | throws_ok { |
40 | $sqla->dispatch( |
41 | { -type => 'alias', ident => 2 } # no as, inavlid ident |
42 | ) |
43 | } qr/foobar/, "alias: no as, invalid ident"; |
44 | |
45 | throws_ok { |
46 | $sqla->dispatch( |
627dcb62 |
47 | { -type => 'alias', iden => { -type => 'identifier', elements => ['id'] }, as => 'foo' } # iden not ident |
747f7c21 |
48 | ) |
49 | } qr/foobar/, "alias: iden instead of ident"; |
ef0d6124 |
50 | |
d4656fcf |
51 | } |
52 | |
53 | throws_ok { |
54 | $sqla->dispatch( |
55 | { -type => 'update', |
56 | tablespec => mk_name('test'), |
57 | columns => [ |
58 | mk_name(qw/me id/), |
59 | mk_alias(mk_name(qw/foo id/) ,'foo_id') |
60 | ] |
61 | } |
62 | ) |
63 | } qr/^'values' is required in update AST/, "Invalid clause in update" |