33use strict;
44use warnings;
55use lib ' t/lib' ;
6- use lib ' t/lib/cached ' ;
6+ use lib ' t/lib/escape ' ;
77use Test::More;
8- use Test::Exception;
98use DodTestUtil;
109
1110BEGIN {
1211 DodTestUtil-> check_driver;
13-
14- unless (eval { require Cache::Memory }) {
15- plan skip_all => ' Tests require Cache::Memory' ;
16- }
1712}
1813
1914plan tests => 6;
@@ -22,70 +17,70 @@ use Foo;
2217
2318setup_dbs({ global => [' foo' ] });
2419
25- my $foo1 = Foo-> new;
26- $foo1 -> name(' foo ' );
27- $foo1 -> text(' 100%' );
28- $foo1 -> save;
20+ my $percent = Foo-> new;
21+ $percent -> name(' percent ' );
22+ $percent -> text(' 100%' );
23+ $percent -> save;
2924
30- my $foo2 = Foo-> new;
31- $foo2 -> name(' bar ' );
32- $foo2 -> text(' 100_' );
33- $foo2 -> save;
25+ my $underscore = Foo-> new;
26+ $underscore -> name(' underscore ' );
27+ $underscore -> text(' 100_' );
28+ $underscore -> save;
3429
35- my $foo3 = Foo-> new;
36- $foo3 -> name(' bar ' );
37- $foo3 -> text(' 100!' );
38- $foo3 -> save;
30+ my $exclamation = Foo-> new;
31+ $exclamation -> name(' exclamation ' );
32+ $exclamation -> text(' 100!' );
33+ $exclamation -> save;
3934
4035subtest ' escape_char 1' => sub {
4136 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100!%' , escape => ' !' } });
4237 is scalar (@got ), 1, ' right number' ;
43- is $got [0]-> name, ' foo ' , ' right name' ;
38+ is $got [0]-> name, ' percent ' , ' right name' ;
4439};
4540
4641subtest ' escape_char 2' => sub {
4742 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100#_' , escape => ' #' } });
4843 is scalar (@got ), 1, ' right number' ;
49- is $got [0]-> name, ' bar ' , ' right name' ;
44+ is $got [0]-> name, ' underscore ' , ' right name' ;
5045};
5146
5247subtest ' self escape' => sub {
5348 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100!!' , escape => ' !' } });
5449 is scalar (@got ), 1, ' right number' ;
55- is $got [0]-> name, ' bar ' , ' right name' ;
50+ is $got [0]-> name, ' exclamation ' , ' right name' ;
5651};
5752
5853subtest ' use wildcard charactor as escapr_char' => sub {
5954 plan skip_all => ' MariaDB does not support it' if Foo-> driver-> dbh-> {Driver }-> {Name } eq ' MariaDB' ;
6055 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100_%' , escape => ' _' } });
6156 is scalar (@got ), 1, ' right number' ;
62- is $got [0]-> name, ' foo ' , ' right name' ;
57+ is $got [0]-> name, ' percent ' , ' right name' ;
6358};
6459
6560subtest ' use of special characters' => sub {
6661 subtest ' escape_char single quote' => sub {
6762 my @got = Foo-> search({ text => { op => ' LIKE' , value => " 100'_" , escape => " ''" } });
6863 is scalar (@got ), 1, ' right number' ;
69- is $got [0]-> name, ' bar ' , ' right name' ;
64+ is $got [0]-> name, ' underscore ' , ' right name' ;
7065 };
7166
7267 if (Foo-> driver-> dbh-> {Driver }-> {Name } =~ / mysql|mariadb/i ) {
7368 subtest ' escape_char single quote' => sub {
7469 my @got = Foo-> search({ text => { op => ' LIKE' , value => " 100'_" , escape => " \\ '" } });
7570 is scalar (@got ), 1, ' right number' ;
76- is $got [0]-> name, ' bar ' , ' right name' ;
71+ is $got [0]-> name, ' underscore ' , ' right name' ;
7772 };
7873
7974 subtest ' escape_char backslash' => sub {
8075 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100\\ _' , escape => ' \\\\ ' } });
8176 is scalar (@got ), 1, ' right number' ;
82- is $got [0]-> name, ' bar ' , ' right name' ;
77+ is $got [0]-> name, ' underscore ' , ' right name' ;
8378 };
8479 } else {
8580 subtest ' escape_char backslash' => sub {
8681 my @got = Foo-> search({ text => { op => ' LIKE' , value => ' 100\\ _' , escape => ' \\ ' } });
8782 is scalar (@got ), 1, ' right number' ;
88- is $got [0]-> name, ' bar ' , ' right name' ;
83+ is $got [0]-> name, ' underscore ' , ' right name' ;
8984 };
9085 }
9186};
0 commit comments