1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
use t::lib::Test;
use Test::More;
BEGIN {
require DBD::SQLite;
if (DBD::SQLite->can('compile_options')
&& grep /ENABLE_ICU/, DBD::SQLite::compile_options()) {
plan( tests => 16 );
} else {
plan( skip_all => 'requires SQLite ICU plugin to be enabled' );
}
}
# use Test::NoWarnings;
my @isochars = (ord("K"), 0xf6, ord("n"), ord("i"), ord("g"));
my $koenig = pack("U*", @isochars);
my $konig = 'konig';
utf8::encode($koenig);
{ # without ICU
my @expected = ($koenig, $konig);
my $dbh = connect_ok();
$dbh->do('create table foo (bar text)');
foreach my $str (reverse @expected) {
$dbh->do('insert into foo values(?)', undef, $str);
}
my $sth = $dbh->prepare('select bar from foo order by bar');
$sth->execute;
my @got;
while(my ($value) = $sth->fetchrow_array) {
push @got, $value;
}
for (my $i = 0; $i < @expected; $i++) {
is $got[$i] => $expected[$i], "got: $got[$i]";
}
}
{ # with ICU
my @expected = ($konig, $koenig);
my $dbh = connect_ok();
eval { $dbh->do('select icu_load_collation("de_DE", "german")') };
ok !$@, "installed icu collation";
# XXX: as of this writing, a warning is known to be printed.
$dbh->do('create table foo (bar text collate german)');
foreach my $str (reverse @expected) {
$dbh->do('insert into foo values(?)', undef, $str);
}
my $sth = $dbh->prepare('select bar from foo order by bar');
$sth->execute;
my @got;
while(my ($value) = $sth->fetchrow_array) {
push @got, $value;
}
for (my $i = 0; $i < @expected; $i++) {
is $got[$i] => $expected[$i], "got: $got[$i]";
}
}
{ # more ICU
my @expected = qw(
flusse
Flusse
fluße
Fluße
flüsse
flüße
Fuße
);
my $dbh = connect_ok();
eval { $dbh->do('select icu_load_collation("de_DE", "german")') };
ok !$@, "installed icu collation";
# XXX: as of this writing, a warning is known to be printed.
$dbh->do('create table foo (bar text collate german)');
foreach my $str (reverse @expected) {
$dbh->do('insert into foo values(?)', undef, $str);
}
my $sth = $dbh->prepare('select bar from foo order by bar');
$sth->execute;
my @got;
while(my ($value) = $sth->fetchrow_array) {
push @got, $value;
}
for (my $i = 0; $i < @expected; $i++) {
is $got[$i] => $expected[$i], "got: $got[$i]";
}
}
|