sl@0
|
1 |
# 2007 May 1
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# $Id: icu.test,v 1.2 2008/07/12 14:52:20 drh Exp $
|
sl@0
|
13 |
#
|
sl@0
|
14 |
|
sl@0
|
15 |
set testdir [file dirname $argv0]
|
sl@0
|
16 |
source $testdir/tester.tcl
|
sl@0
|
17 |
|
sl@0
|
18 |
ifcapable !icu {
|
sl@0
|
19 |
finish_test
|
sl@0
|
20 |
return
|
sl@0
|
21 |
}
|
sl@0
|
22 |
|
sl@0
|
23 |
# Create a table to work with.
|
sl@0
|
24 |
#
|
sl@0
|
25 |
execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
|
sl@0
|
26 |
execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
|
sl@0
|
27 |
proc test_expr {name settings expr result} {
|
sl@0
|
28 |
do_test $name [format {
|
sl@0
|
29 |
db one {
|
sl@0
|
30 |
BEGIN;
|
sl@0
|
31 |
UPDATE test1 SET %s;
|
sl@0
|
32 |
SELECT %s FROM test1;
|
sl@0
|
33 |
ROLLBACK;
|
sl@0
|
34 |
}
|
sl@0
|
35 |
} $settings $expr] $result
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
# Tests of the REGEXP operator.
|
sl@0
|
39 |
#
|
sl@0
|
40 |
test_expr icu-1.1 {i1='hello'} {i1 REGEXP 'hello'} 1
|
sl@0
|
41 |
test_expr icu-1.2 {i1='hello'} {i1 REGEXP '.ello'} 1
|
sl@0
|
42 |
test_expr icu-1.3 {i1='hello'} {i1 REGEXP '.ell'} 0
|
sl@0
|
43 |
test_expr icu-1.4 {i1='hello'} {i1 REGEXP '.ell.*'} 1
|
sl@0
|
44 |
test_expr icu-1.5 {i1=NULL} {i1 REGEXP '.ell.*'} {}
|
sl@0
|
45 |
|
sl@0
|
46 |
# Some non-ascii characters with defined case mappings
|
sl@0
|
47 |
#
|
sl@0
|
48 |
set ::EGRAVE "\xC8"
|
sl@0
|
49 |
set ::egrave "\xE8"
|
sl@0
|
50 |
|
sl@0
|
51 |
set ::OGRAVE "\xD2"
|
sl@0
|
52 |
set ::ograve "\xF2"
|
sl@0
|
53 |
|
sl@0
|
54 |
# That German letter that looks a bit like a B. The
|
sl@0
|
55 |
# upper-case version of which is "SS" (two characters).
|
sl@0
|
56 |
#
|
sl@0
|
57 |
set ::szlig "\xDF"
|
sl@0
|
58 |
|
sl@0
|
59 |
# Tests of the upper()/lower() functions.
|
sl@0
|
60 |
#
|
sl@0
|
61 |
test_expr icu-2.1 {i1='HellO WorlD'} {upper(i1)} {HELLO WORLD}
|
sl@0
|
62 |
test_expr icu-2.2 {i1='HellO WorlD'} {lower(i1)} {hello world}
|
sl@0
|
63 |
test_expr icu-2.3 {i1=$::egrave} {lower(i1)} $::egrave
|
sl@0
|
64 |
test_expr icu-2.4 {i1=$::egrave} {upper(i1)} $::EGRAVE
|
sl@0
|
65 |
test_expr icu-2.5 {i1=$::ograve} {lower(i1)} $::ograve
|
sl@0
|
66 |
test_expr icu-2.6 {i1=$::ograve} {upper(i1)} $::OGRAVE
|
sl@0
|
67 |
test_expr icu-2.3 {i1=$::EGRAVE} {lower(i1)} $::egrave
|
sl@0
|
68 |
test_expr icu-2.4 {i1=$::EGRAVE} {upper(i1)} $::EGRAVE
|
sl@0
|
69 |
test_expr icu-2.5 {i1=$::OGRAVE} {lower(i1)} $::ograve
|
sl@0
|
70 |
test_expr icu-2.6 {i1=$::OGRAVE} {upper(i1)} $::OGRAVE
|
sl@0
|
71 |
|
sl@0
|
72 |
test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS"
|
sl@0
|
73 |
test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss"
|
sl@0
|
74 |
|
sl@0
|
75 |
# In turkish (locale="tr_TR"), the lower case version of I
|
sl@0
|
76 |
# is "small dotless i" (code point 0x131 (decimal 305)).
|
sl@0
|
77 |
#
|
sl@0
|
78 |
set ::small_dotless_i "\u0131"
|
sl@0
|
79 |
test_expr icu-3.1 {i1='I'} {lower(i1)} "i"
|
sl@0
|
80 |
test_expr icu-3.2 {i1='I'} {lower(i1, 'tr_tr')} $::small_dotless_i
|
sl@0
|
81 |
test_expr icu-3.3 {i1='I'} {lower(i1, 'en_AU')} "i"
|
sl@0
|
82 |
|
sl@0
|
83 |
#--------------------------------------------------------------------
|
sl@0
|
84 |
# Test the collation sequence function.
|
sl@0
|
85 |
#
|
sl@0
|
86 |
do_test icu-4.1 {
|
sl@0
|
87 |
execsql {
|
sl@0
|
88 |
CREATE TABLE fruit(name);
|
sl@0
|
89 |
INSERT INTO fruit VALUES('plum');
|
sl@0
|
90 |
INSERT INTO fruit VALUES('cherry');
|
sl@0
|
91 |
INSERT INTO fruit VALUES('apricot');
|
sl@0
|
92 |
INSERT INTO fruit VALUES('peach');
|
sl@0
|
93 |
INSERT INTO fruit VALUES('chokecherry');
|
sl@0
|
94 |
INSERT INTO fruit VALUES('yamot');
|
sl@0
|
95 |
}
|
sl@0
|
96 |
} {}
|
sl@0
|
97 |
do_test icu-4.2 {
|
sl@0
|
98 |
execsql {
|
sl@0
|
99 |
SELECT icu_load_collation('en_US', 'AmericanEnglish');
|
sl@0
|
100 |
SELECT icu_load_collation('lt_LT', 'Lithuanian');
|
sl@0
|
101 |
}
|
sl@0
|
102 |
execsql {
|
sl@0
|
103 |
SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
} {apricot cherry chokecherry peach plum yamot}
|
sl@0
|
106 |
|
sl@0
|
107 |
|
sl@0
|
108 |
# Test collation using Lithuanian rules. In the Lithuanian
|
sl@0
|
109 |
# alphabet, "y" comes right after "i".
|
sl@0
|
110 |
#
|
sl@0
|
111 |
do_test icu-4.3 {
|
sl@0
|
112 |
execsql {
|
sl@0
|
113 |
SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
} {apricot cherry chokecherry yamot peach plum}
|
sl@0
|
116 |
|
sl@0
|
117 |
finish_test
|