Make join tests behave
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 200_join.t
CommitLineData
704c5138 1use strict;
2use warnings;
3
d0ad3a92 4use Test::More tests => 4;
704c5138 5use Test::Differences;
6
7use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
8
9my $sqla = SQL::Abstract->create(1);
10
f7dc4536 11my $foo = {-type => name => args => [qw/foo/]};
12my $bar = {-type => name => args => [qw/bar/]},
13my $fnord = {-type => name => args => [qw/fnord/]};
14
15my $foo_id = { -type => 'name', args => [qw/foo id/] };
16my $me_foo_id = { -type => 'name', args => [qw/me foo_id/] };
17
704c5138 18is $sqla->dispatch(
cbcfedc1 19 { -type => 'join',
f7dc4536 20 lhs => $bar,
21 rhs => $foo,
747f7c21 22 on => {
23 -type => 'expr',
24 op => '==',
f7dc4536 25 args => [ $foo_id, $me_foo_id ]
747f7c21 26 }
cbcfedc1 27 }
d0ad3a92 28), "bar JOIN foo ON (foo.id = me.foo_id)",
704c5138 29 "simple join clause";
30
f7dc4536 31
32$foo_id = { -type => 'name', args => [qw/foo_id/] };
33
cbcfedc1 34is $sqla->dispatch(
35 { -type => 'join',
f7dc4536 36 lhs => $fnord,
37 rhs => {-type => 'alias', ident => $foo, as => 'bar' },
38 using => $foo_id
cbcfedc1 39 }
d0ad3a92 40), "fnord JOIN foo AS bar USING (foo_id)",
cbcfedc1 41 "using join clause";
d0ad3a92 42
43
44is $sqla->dispatch(
45 { -type => 'join',
46 join_type => 'LEFT',
f7dc4536 47 lhs => $fnord,
48 rhs => {-type => 'alias', ident => $foo, as => 'bar' },
49 using => $foo_id
d0ad3a92 50 }
51), "fnord LEFT JOIN foo AS bar USING (foo_id)",
52 "using left join clause";