1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00
DBD-SQLite-SQLcipher/t/37_regexp.t
Laurent Dami 3714dc6954 - Added support for commit/rollback/update hooks (DAMI)
- Added support for set_authorizer (DAMI)
    - Added support for collation_needed(), and reorganised driver API
      for user-defined collations (DAMI)
    - Exported constants from sqlite3.h into DBD::SQLite namespace (DAMI)
    - Added support in t/lib/Test.pm for checking both versions of
      driver-private methods ("func" / "sqlite_*") (DAMI)
    - Removed unused and obsolete "list_tables" from SQLite.xs (DAMI)
    - Added a default implementation for the REGEXP infix operator (DAMI)
2009-07-20 10:20:09 +00:00

74 lines
1.9 KiB
Perl

#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More;
use Test::NoWarnings;
my @words = qw{
berger Bergère bergère Bergere
HOT hôte
hétéroclite hétaïre hêtre héraut
HAT hâter
fétu fête fève ferme
};
my @regexes = qw( ^b\\w+ (?i:^b\\w+) );
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
plan skip_all => 'Unicode is not supported before 5.8.5'
if $] < 5.008005;
plan tests => 2 * (1 + 2 * @regexes) * @CALL_FUNCS + 1 ;
BEGIN {
# Sadly perl for windows (and probably sqlite, too) may hang
# if the system locale doesn't support european languages.
# en-us should be a safe default. if it doesn't work, use 'C'.
if ( $^O eq 'MSWin32') {
use POSIX 'locale_h';
setlocale(LC_COLLATE, 'en-us');
}
}
use locale;
use DBD::SQLite;
foreach my $call_func (@CALL_FUNCS) {
for my $use_unicode (0, 1) {
# connect
my $dbh = connect_ok( RaiseError => 1, unicode => $use_unicode );
# populate test data
my @vals = @words;
if ($use_unicode) {
utf8::upgrade($_) foreach @vals;
}
$dbh->do( 'CREATE TEMP TABLE regexp_test ( txt )' );
$dbh->do( "INSERT INTO regexp_test VALUES ( '$_' )" ) foreach @vals;
foreach my $regex (@regexes) {
my @perl_match = grep {/$regex/} @vals;
my $sql = "SELECT txt from regexp_test WHERE txt REGEXP '$regex' "
. "COLLATE perllocale";
my $db_match = $dbh->selectcol_arrayref($sql);
is_deeply(\@perl_match, $db_match, "REGEXP '$regex'");
my @perl_antimatch = grep {!/$regex/} @vals;
$sql =~ s/REGEXP/NOT REGEXP/;
my $db_antimatch = $dbh->selectcol_arrayref($sql);
is_deeply(\@perl_antimatch, $db_antimatch, "NOT REGEXP '$regex'");
}
}
}