3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # $Id: icu.test,v 1.2 2008/07/12 14:52:20 drh Exp $
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 ifcapable !icu&&!icu_collations {
23 # Create a table to work with.
25 execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
26 execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
27 proc test_expr {name settings expr result} {
28 do_test $name [format {
35 } $settings $expr] $result
40 # Tests of the REGEXP operator.
42 test_expr icu-1.1 {i1='hello'} {i1 REGEXP 'hello'} 1
43 test_expr icu-1.2 {i1='hello'} {i1 REGEXP '.ello'} 1
44 test_expr icu-1.3 {i1='hello'} {i1 REGEXP '.ell'} 0
45 test_expr icu-1.4 {i1='hello'} {i1 REGEXP '.ell.*'} 1
46 test_expr icu-1.5 {i1=NULL} {i1 REGEXP '.ell.*'} {}
48 # Some non-ascii characters with defined case mappings
56 # That German letter that looks a bit like a B. The
57 # upper-case version of which is "SS" (two characters).
61 # Tests of the upper()/lower() functions.
63 test_expr icu-2.1 {i1='HellO WorlD'} {upper(i1)} {HELLO WORLD}
64 test_expr icu-2.2 {i1='HellO WorlD'} {lower(i1)} {hello world}
65 test_expr icu-2.3 {i1=$::egrave} {lower(i1)} $::egrave
66 test_expr icu-2.4 {i1=$::egrave} {upper(i1)} $::EGRAVE
67 test_expr icu-2.5 {i1=$::ograve} {lower(i1)} $::ograve
68 test_expr icu-2.6 {i1=$::ograve} {upper(i1)} $::OGRAVE
69 test_expr icu-2.3 {i1=$::EGRAVE} {lower(i1)} $::egrave
70 test_expr icu-2.4 {i1=$::EGRAVE} {upper(i1)} $::EGRAVE
71 test_expr icu-2.5 {i1=$::OGRAVE} {lower(i1)} $::ograve
72 test_expr icu-2.6 {i1=$::OGRAVE} {upper(i1)} $::OGRAVE
74 test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS"
75 test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss"
77 do_execsql_test icu-2.9 {
78 SELECT upper(char(0xfb04,0xfb04,0xfb04,0xfb04));
81 # In turkish (locale="tr_TR"), the lower case version of I
82 # is "small dotless i" (code point 0x131 (decimal 305)).
84 set ::small_dotless_i "\u0131"
85 test_expr icu-3.1 {i1='I'} {lower(i1)} "i"
86 test_expr icu-3.2 {i1='I'} {lower(i1, 'tr_tr')} $::small_dotless_i
87 test_expr icu-3.3 {i1='I'} {lower(i1, 'en_AU')} "i"
90 #--------------------------------------------------------------------
91 # Test the collation sequence function.
95 CREATE TABLE fruit(name);
96 INSERT INTO fruit VALUES('plum');
97 INSERT INTO fruit VALUES('cherry');
98 INSERT INTO fruit VALUES('apricot');
99 INSERT INTO fruit VALUES('peach');
100 INSERT INTO fruit VALUES('chokecherry');
101 INSERT INTO fruit VALUES('yamot');
106 SELECT icu_load_collation('en_US', 'AmericanEnglish');
107 SELECT icu_load_collation('lt_LT', 'Lithuanian');
110 SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC;
112 } {apricot cherry chokecherry peach plum yamot}
115 # Test collation using Lithuanian rules. In the Lithuanian
116 # alphabet, "y" comes right after "i".
120 SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC;
122 } {apricot cherry chokecherry yamot peach plum}
124 #-------------------------------------------------------------------------
125 # Test that it is not possible to call the ICU regex() function with
126 # anything other than exactly two arguments. See also:
128 # http://src.chromium.org/viewvc/chrome/trunk/src/third_party/sqlite/icu-regexp.patch?revision=34807&view=markup
131 do_catchsql_test icu-5.1 { SELECT regexp('a[abc]c.*', 'abc') } {0 1}
132 do_catchsql_test icu-5.2 {
133 SELECT regexp('a[abc]c.*')
134 } {1 {wrong number of arguments to function regexp()}}
135 do_catchsql_test icu-5.3 {
136 SELECT regexp('a[abc]c.*', 'abc', 'c')
137 } {1 {wrong number of arguments to function regexp()}}
138 do_catchsql_test icu-5.4 {
139 SELECT 'abc' REGEXP 'a[abc]c.*'
141 do_catchsql_test icu-5.5 {SELECT 'abc' REGEXP } {1 {incomplete input}}
142 do_catchsql_test icu-5.6 {SELECT 'abc' REGEXP, 1} {1 {near ",": syntax error}}
144 do_malloc_test icu-6.10 -sqlbody {
145 SELECT upper(char(0xfb04,0xdf,0xfb04,0xe8,0xfb04));
150 # The ESCAPE clause on LIKE takes precedence over wildcards
152 do_execsql_test idu-6.0 {
153 DROP TABLE IF EXISTS t1;
154 CREATE TABLE t1(id INTEGER PRIMARY KEY, x TEXT);
155 INSERT INTO t1 VALUES
161 SELECT id FROM t1 WHERE x LIKE 'abc%%' ESCAPE '%';
163 do_execsql_test icu-6.1 {
164 SELECT id FROM t1 WHERE x LIKE 'abc__' ESCAPE '_';