8 # use a BEGIN block so we print our plan before SQL::Abstract is loaded
9 BEGIN { plan tests => 4 }
14 my ($got, $expect, $msg) = @_;
15 ok($got eq $expect) or
16 warn "got [${got}]\ninstead of [${expect}]\nfor test ${msg}\n\n";
19 my $sa = new SQL::Abstract;
22 { child => 'person' },
23 [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ],
24 [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ],
26 my $match = 'person child JOIN person father ON ( father.person_id = '
27 . 'child.father_id ) JOIN person mother ON ( mother.person_id '
28 . '= child.mother_id )'
30 is( $sa->_recurse_from(@j), $match, 'join 1 ok' );
33 { mother => 'person' },
34 [ [ { child => 'person' },
35 [ { father => 'person' },
36 { 'father.person_id' => 'child.father_id' }
39 { 'mother.person_id' => 'child.mother_id' }
42 $match = 'person mother JOIN (person child JOIN person father ON ('
43 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
46 is( $sa->_recurse_from(@j2), $match, 'join 2 ok' );
49 { child => 'person' },
50 [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ],
51 [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ],
53 $match = 'person child INNER JOIN person father ON ( father.person_id = '
54 . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id '
55 . '= child.mother_id )'
58 is( $sa->_recurse_from(@j3), $match, 'join 3 (inner join) ok');
61 { mother => 'person' },
62 [ [ { child => 'person', -join_type => 'left' },
63 [ { father => 'person', -join_type => 'right' },
64 { 'father.person_id' => 'child.father_id' }
67 { 'mother.person_id' => 'child.mother_id' }
70 $match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON ('
71 . ' father.person_id = child.father_id )) ON ( mother.person_id = '
74 is( $sa->_recurse_from(@j4), $match, 'join 4 (nested joins + join types) ok');