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
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
38 # Tests of the REGEXP operator.
40 test_expr icu-1.1 {i1='hello'} {i1 REGEXP 'hello'} 1
41 test_expr icu-1.2 {i1='hello'} {i1 REGEXP '.ello'} 1
42 test_expr icu-1.3 {i1='hello'} {i1 REGEXP '.ell'} 0
43 test_expr icu-1.4 {i1='hello'} {i1 REGEXP '.ell.*'} 1
44 test_expr icu-1.5 {i1=NULL} {i1 REGEXP '.ell.*'} {}
46 # Some non-ascii characters with defined case mappings
54 # That German letter that looks a bit like a B. The
55 # upper-case version of which is "SS" (two characters).
59 # Tests of the upper()/lower() functions.
61 test_expr icu-2.1 {i1='HellO WorlD'} {upper(i1)} {HELLO WORLD}
62 test_expr icu-2.2 {i1='HellO WorlD'} {lower(i1)} {hello world}
63 test_expr icu-2.3 {i1=$::egrave} {lower(i1)} $::egrave
64 test_expr icu-2.4 {i1=$::egrave} {upper(i1)} $::EGRAVE
65 test_expr icu-2.5 {i1=$::ograve} {lower(i1)} $::ograve
66 test_expr icu-2.6 {i1=$::ograve} {upper(i1)} $::OGRAVE
67 test_expr icu-2.3 {i1=$::EGRAVE} {lower(i1)} $::egrave
68 test_expr icu-2.4 {i1=$::EGRAVE} {upper(i1)} $::EGRAVE
69 test_expr icu-2.5 {i1=$::OGRAVE} {lower(i1)} $::ograve
70 test_expr icu-2.6 {i1=$::OGRAVE} {upper(i1)} $::OGRAVE
72 test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS"
73 test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss"
75 do_execsql_test icu-2.9 {
76 SELECT upper(char(0xfb04,0xfb04,0xfb04,0xfb04));
79 # In turkish (locale="tr_TR"), the lower case version of I
80 # is "small dotless i" (code point 0x131 (decimal 305)).
82 set ::small_dotless_i "\u0131"
83 test_expr icu-3.1 {i1='I'} {lower(i1)} "i"
84 test_expr icu-3.2 {i1='I'} {lower(i1, 'tr_tr')} $::small_dotless_i
85 test_expr icu-3.3 {i1='I'} {lower(i1, 'en_AU')} "i"
87 #--------------------------------------------------------------------
88 # Test the collation sequence function.
92 CREATE TABLE fruit(name);
93 INSERT INTO fruit VALUES('plum');
94 INSERT INTO fruit VALUES('cherry');
95 INSERT INTO fruit VALUES('apricot');
96 INSERT INTO fruit VALUES('peach');
97 INSERT INTO fruit VALUES('chokecherry');
98 INSERT INTO fruit VALUES('yamot');
103 SELECT icu_load_collation('en_US', 'AmericanEnglish');
104 SELECT icu_load_collation('lt_LT', 'Lithuanian');
107 SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC;
109 } {apricot cherry chokecherry peach plum yamot}
112 # Test collation using Lithuanian rules. In the Lithuanian
113 # alphabet, "y" comes right after "i".
117 SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC;
119 } {apricot cherry chokecherry yamot peach plum}
121 #-------------------------------------------------------------------------
122 # Test that it is not possible to call the ICU regex() function with
123 # anything other than exactly two arguments. See also:
125 # http://src.chromium.org/viewvc/chrome/trunk/src/third_party/sqlite/icu-regexp.patch?revision=34807&view=markup
127 do_catchsql_test icu-5.1 { SELECT regexp('a[abc]c.*', 'abc') } {0 1}
128 do_catchsql_test icu-5.2 {
129 SELECT regexp('a[abc]c.*')
130 } {1 {wrong number of arguments to function regexp()}}
131 do_catchsql_test icu-5.3 {
132 SELECT regexp('a[abc]c.*', 'abc', 'c')
133 } {1 {wrong number of arguments to function regexp()}}
134 do_catchsql_test icu-5.4 {
135 SELECT 'abc' REGEXP 'a[abc]c.*'
137 do_catchsql_test icu-5.4 { SELECT 'abc' REGEXP } {1 {near " ": syntax error}}
138 do_catchsql_test icu-5.5 { SELECT 'abc' REGEXP, 1 } {1 {near ",": syntax error}}
141 do_malloc_test icu-6.10 -sqlbody {
142 SELECT upper(char(0xfb04,0xdf,0xfb04,0xe8,0xfb04));