From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

#!/usr/bin/perl -w
use strict;
use lib qw(t);
my($stmt,$cache)=(undef,{});
my $p = SQL::Parser->new();
ok(cmp_parse('SELECT 1', 'SELECT 1'), 'sanity check');
foreach my $op (qw( <> <= >= )) {
ok(cmp_parse(
"SELECT * FROM x WHERE col1 ${op} col2",
"SELECT * FROM x WHERE col1${op}col2"
), "'${op}' without spaces");
}
done_testing();
sub cmp_parse {
my ($sql_given,$sql_want) = @_;
my($stmt_given,$stmt_want);
eval {
$stmt_given = SQL::Statement->new($sql_given,$p);
$stmt_want = SQL::Statement->new($sql_want,$p);
};
return 0 if $@;
foreach (qw(
command
columns
column_aliases
tables
)) {
return 0 if !eq_deeply($stmt_given->{$_}, $stmt_want->{$_});
}
return 1;
}