blob: 644cbb1f08f7f4af42e8a0dc1f1d5bc1e95e47c0 [file] [log] [blame]
danielk197725591362007-05-07 11:53:13 +00001# 2007 May 1
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11#
drhe8f52c52008-07-12 14:52:20 +000012# $Id: icu.test,v 1.2 2008/07/12 14:52:20 drh Exp $
danielk197725591362007-05-07 11:53:13 +000013#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
dan21540ae2017-12-08 16:23:38 +000018ifcapable !icu&&!icu_collations {
danielk197725591362007-05-07 11:53:13 +000019 finish_test
20 return
21}
22
23# Create a table to work with.
24#
25execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
26execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
27proc test_expr {name settings expr result} {
28 do_test $name [format {
dan1476a282009-10-17 14:19:29 +000029 lindex [db eval {
danielk197725591362007-05-07 11:53:13 +000030 BEGIN;
31 UPDATE test1 SET %s;
32 SELECT %s FROM test1;
33 ROLLBACK;
dan1476a282009-10-17 14:19:29 +000034 }] 0
danielk197725591362007-05-07 11:53:13 +000035 } $settings $expr] $result
36}
37
dan21540ae2017-12-08 16:23:38 +000038ifcapable icu {
danielk197725591362007-05-07 11:53:13 +000039
dan21540ae2017-12-08 16:23:38 +000040 # Tests of the REGEXP operator.
41 #
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.*'} {}
danielk197725591362007-05-07 11:53:13 +000047
dan21540ae2017-12-08 16:23:38 +000048 # Some non-ascii characters with defined case mappings
49 #
50 set ::EGRAVE "\xC8"
51 set ::egrave "\xE8"
danielk197725591362007-05-07 11:53:13 +000052
dan21540ae2017-12-08 16:23:38 +000053 set ::OGRAVE "\xD2"
54 set ::ograve "\xF2"
danielk197725591362007-05-07 11:53:13 +000055
dan21540ae2017-12-08 16:23:38 +000056 # That German letter that looks a bit like a B. The
57 # upper-case version of which is "SS" (two characters).
58 #
59 set ::szlig "\xDF"
danielk197725591362007-05-07 11:53:13 +000060
dan21540ae2017-12-08 16:23:38 +000061 # Tests of the upper()/lower() functions.
62 #
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
danielk197725591362007-05-07 11:53:13 +000073
dan21540ae2017-12-08 16:23:38 +000074 test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS"
75 test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss"
drh88a16502016-02-26 21:20:57 +000076
dan21540ae2017-12-08 16:23:38 +000077 do_execsql_test icu-2.9 {
78 SELECT upper(char(0xfb04,0xfb04,0xfb04,0xfb04));
79 } {FFLFFLFFLFFL}
80
81 # In turkish (locale="tr_TR"), the lower case version of I
82 # is "small dotless i" (code point 0x131 (decimal 305)).
83 #
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"
88}
danielk197725591362007-05-07 11:53:13 +000089
90#--------------------------------------------------------------------
91# Test the collation sequence function.
92#
93do_test icu-4.1 {
94 execsql {
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');
102 }
103} {}
104do_test icu-4.2 {
105 execsql {
106 SELECT icu_load_collation('en_US', 'AmericanEnglish');
107 SELECT icu_load_collation('lt_LT', 'Lithuanian');
108 }
109 execsql {
110 SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC;
111 }
112} {apricot cherry chokecherry peach plum yamot}
113
114
115# Test collation using Lithuanian rules. In the Lithuanian
116# alphabet, "y" comes right after "i".
117#
118do_test icu-4.3 {
119 execsql {
120 SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC;
121 }
122} {apricot cherry chokecherry yamot peach plum}
123
dan3843a4c2010-07-30 05:06:05 +0000124#-------------------------------------------------------------------------
125# Test that it is not possible to call the ICU regex() function with
126# anything other than exactly two arguments. See also:
127#
128# http://src.chromium.org/viewvc/chrome/trunk/src/third_party/sqlite/icu-regexp.patch?revision=34807&view=markup
129#
dan21540ae2017-12-08 16:23:38 +0000130ifcapable icu {
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.*'
140 } {0 1}
drh6116ee42018-01-10 00:40:06 +0000141 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}}
dan21540ae2017-12-08 16:23:38 +0000143
144 do_malloc_test icu-6.10 -sqlbody {
145 SELECT upper(char(0xfb04,0xdf,0xfb04,0xe8,0xfb04));
146 }
drh88a16502016-02-26 21:20:57 +0000147}
148
drh589c7872020-03-19 18:13:28 +0000149# 2020-03-19
150# The ESCAPE clause on LIKE takes precedence over wildcards
151#
152do_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
156 (1,'abcde'),
157 (2,'abc_'),
158 (3,'abc__'),
159 (4,'abc%'),
160 (5,'abc%%');
161 SELECT id FROM t1 WHERE x LIKE 'abc%%' ESCAPE '%';
162} {4}
163do_execsql_test icu-6.1 {
164 SELECT id FROM t1 WHERE x LIKE 'abc__' ESCAPE '_';
165} {2}
166
danielk197725591362007-05-07 11:53:13 +0000167finish_test