Make join tests behave
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 201_select.t
CommitLineData
4ee32f41 1use strict;
2use warnings;
3
4use Test::More tests => 3;
5use Test::Differences;
6
7use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
8
9my $sqla = SQL::Abstract->create(1);
10
11is $sqla->dispatch(
12 { -type => 'select',
747f7c21 13 tablespec => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
14 columns => [
15 { -type => 'name', args => [qw/me id/] },
16 { -type => 'alias', ident => { -type => 'name', args => [qw/me foo_id/] }, as => 'foo' },
4ee32f41 17 ]
18 }
19), "SELECT me.id, me.foo_id AS foo FROM foo AS me",
20 "simple select clause";
21
22is $sqla->dispatch(
23 { -type => 'select',
747f7c21 24 columns => [
25 { -type => 'name', args => [qw/me id/] },
26 { -type => 'alias', ident => { -type => 'name', args => [qw/me foo_id/] }, as => 'foo' },
27 { -type => 'name', args => [qw/bar name/] },
64c32031 28 ],
29 tablespec => {
30 -type => 'join',
f7dc4536 31 lhs => {-type => 'alias', ident => {-type => 'name', args => [qw/foo/]}, as => 'me' },
32 rhs => {-type => 'name', args => [qw/bar/] },
64c32031 33 on => {
34 -type => 'expr',
35 op => '==',
36 args => [
37 {-type => 'name', args => [qw/bar id/]},
38 {-type => 'name', args => [qw/me bar_id/]}
39 ],
40 }
41 },
747f7c21 42 }
43
44
4ee32f41 45), "SELECT me.id, me.foo_id AS foo, bar.name FROM foo AS me JOIN bar ON (bar.id = me.bar_id)",
46 "select with join clause";
47
64c32031 48__END__