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