File: rt_084972.t

package info (click to toggle)
libsql-abstract-more-perl 1.44-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264 kB
  • sloc: perl: 1,039; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strict;
use warnings;
use Test::More;
use Test::Exception;

use SQL::Abstract::More;
use SQL::Abstract::Test import => ['eq_sql'];
use List::MoreUtils qw/any/;

plan tests => 2;


my $sqla  = SQL::Abstract::More->new;

my $result = $sqla->join(
  'table',
  { operator => '=>',
    condition => { '%1$s.table_id' => {-ident => '%2$s.table_id'},
                   '%2$s.date'     => {'>' => {-ident => '%1$s.date'}},
                   '%2$s.event_id' => 1}},
  'table_log'
);

# we don't know the order of conditions generated by SQL::Abstract;
# but unfortunately, SQL::Abstract::Test is not clever enough to apply
# commutativity on AND, so we have to do it by hand

my @conditions = (
  'table_log.date     > table.date',
  'table.table_id     = table_log.table_id',
  'table_log.event_id = ?',
);

my @possible_SQL = map {"table LEFT OUTER JOIN table_log ON "
                        . join(' AND ', @$_) } permutations(@conditions);

ok (any { eq_sql($result->{sql}, $_) } @possible_SQL);
is_deeply ($result->{bind}, [1]);



sub permutations {
  return \@_ if @_ < 2;

  my @result;
  for my $i (0 .. $#_) {
    my @tail = @_;
    my $head = splice(@tail, $i, 1);
    push @result, map {[$head, @$_ ]} permutations(@tail);
  }
  return @result;
}