Start working on update clause
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 900_errors.t
CommitLineData
ef0d6124 1use strict;
2use warnings;
3
d4656fcf 4use Test::More tests => 6;
ef0d6124 5use Test::Exception;
6
d4656fcf 7use FindBin;
8use lib "$FindBin::Bin/lib";
9use Test::SQL::Abstract::Util qw/
10 mk_name
11 mk_value
12 mk_alias
13/;
14
ef0d6124 15use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
16
17my $sqla = SQL::Abstract->create(1);
18
19throws_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
30throws_ok {
31 $sqla->dispatch(
32 { -type => 'expr', op => '~' }
33 )
747f7c21 34} qr/^'~' is not a valid operator in an expression/;
35
d4656fcf 36{
747f7c21 37local $TODO = "Work out how to get nice errors for these";
38
39throws_ok {
40 $sqla->dispatch(
41 { -type => 'alias', ident => 2 } # no as, inavlid ident
42 )
43} qr/foobar/, "alias: no as, invalid ident";
44
45throws_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
53throws_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"