Skip to content

Commit

Permalink
fix test for MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadam committed Oct 22, 2024
1 parent b389411 commit 5bec099
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions t/61-escape.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BEGIN {
}
}

plan tests => 5;
plan tests => 6;

use Foo;

Expand All @@ -32,6 +32,11 @@ $foo2->name('bar');
$foo2->text('100_');
$foo2->save;

my $foo3 = Foo->new;
$foo3->name('bar');
$foo3->text('100!');
$foo3->save;

subtest 'escape_char 1' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100!%', escape => '!' } });
is scalar(@got), 1, 'right number';
Expand All @@ -45,19 +50,26 @@ subtest 'escape_char 2' => sub {
};

subtest 'self escape' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100__', escape => '_' } });
my @got = Foo->search({ text => { op => 'LIKE', value => '100!!', escape => '!' } });
is scalar(@got), 1, 'right number';
is $got[0]->name, 'bar', 'right name';
};

subtest 'use wildcard charactor as escapr_char' => sub {
plan skip_all => 'MariaDB does not support it' if Foo->driver->dbh->{Driver}->{Name} eq 'MariaDB';
my @got = Foo->search({ text => { op => 'LIKE', value => '100_%', escape => '_' } });
is scalar(@got), 1, 'right number';
is $got[0]->name, 'foo', 'right name';
};

subtest 'use of special characters' => sub {
subtest 'escape_char single quote' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => "100'_", escape => "''" } });
is scalar(@got), 1, 'right number';
is $got[0]->name, 'bar', 'right name';
};

if (Foo->driver->dbh->{Driver}->{Name} eq 'mysql') {
if (Foo->driver->dbh->{Driver}->{Name} =~ /mysql|mariadb/i) {
subtest 'escape_char single quote' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => "100'_", escape => "\\'" } });
is scalar(@got), 1, 'right number';
Expand Down

0 comments on commit 5bec099

Please sign in to comment.