The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

use strict;
use SQL::Maker::SQLType qw/sql_type/;
use DBI qw/:sql_types/;
open my $fh, '<', 'lib/SQL/Maker/Condition.pm' or die "cannot open file: $!";
# skip header
while (<$fh>) {
last if /=head1 CONDITION CHEAT SHEET/;
}
my ($in, $query, @bind);
while (<$fh>) {
$in = $1 if /IN:\s*(.+)\s*$/;
$query = eval $1 if /OUT QUERY:(.+)/;
if (/OUT BIND:(.+)/) {
@bind = eval $1;
test($in, $query, \@bind);
}
}
done_testing;
exit(0);
sub test {
my ($in, $expected_term, $expected_bind) = @_;
subtest $in => sub {
my $source = do {
local $@;
my $source = eval $in;
die $@ if $@;
$source;
};
my $cond = SQL::Maker::Condition->new(
quote_char => q{`},
name_sep => q{.},
);
$cond->add(@$source);
my $sql = $cond->as_sql;
$sql =~ s/^\(//;
$sql =~ s/\)$//;
is $sql, $expected_term;
is_deeply [$cond->bind], $expected_bind;
};
}