125591369Sdanielk1977# 2007 May 1 225591369Sdanielk1977# 325591369Sdanielk1977# The author disclaims copyright to this source code. In place of 425591369Sdanielk1977# a legal notice, here is a blessing: 525591369Sdanielk1977# 625591369Sdanielk1977# May you do good and not evil. 725591369Sdanielk1977# May you find forgiveness for yourself and forgive others. 825591369Sdanielk1977# May you share freely, never taking more than you give. 925591369Sdanielk1977# 1025591369Sdanielk1977#*********************************************************************** 1125591369Sdanielk1977# 12e8f52c50Sdrh# $Id: icu.test,v 1.2 2008/07/12 14:52:20 drh Exp $ 1325591369Sdanielk1977# 1425591369Sdanielk1977 1525591369Sdanielk1977set testdir [file dirname $argv0] 1625591369Sdanielk1977source $testdir/tester.tcl 1725591369Sdanielk1977 1821540ae4Sdanifcapable !icu&&!icu_collations { 1925591369Sdanielk1977 finish_test 2025591369Sdanielk1977 return 2125591369Sdanielk1977} 2225591369Sdanielk1977 2325591369Sdanielk1977# Create a table to work with. 2425591369Sdanielk1977# 2525591369Sdanielk1977execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)} 2625591369Sdanielk1977execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')} 2725591369Sdanielk1977proc test_expr {name settings expr result} { 2825591369Sdanielk1977 do_test $name [format { 291476a284Sdan lindex [db eval { 3025591369Sdanielk1977 BEGIN; 3125591369Sdanielk1977 UPDATE test1 SET %s; 3225591369Sdanielk1977 SELECT %s FROM test1; 3325591369Sdanielk1977 ROLLBACK; 341476a284Sdan }] 0 3525591369Sdanielk1977 } $settings $expr] $result 3625591369Sdanielk1977} 3725591369Sdanielk1977 3821540ae4Sdanifcapable icu { 3921540ae4Sdan 4025591369Sdanielk1977 # Tests of the REGEXP operator. 4125591369Sdanielk1977 # 4225591369Sdanielk1977 test_expr icu-1.1 {i1='hello'} {i1 REGEXP 'hello'} 1 4325591369Sdanielk1977 test_expr icu-1.2 {i1='hello'} {i1 REGEXP '.ello'} 1 4425591369Sdanielk1977 test_expr icu-1.3 {i1='hello'} {i1 REGEXP '.ell'} 0 4525591369Sdanielk1977 test_expr icu-1.4 {i1='hello'} {i1 REGEXP '.ell.*'} 1 4625591369Sdanielk1977 test_expr icu-1.5 {i1=NULL} {i1 REGEXP '.ell.*'} {} 4725591369Sdanielk1977 4825591369Sdanielk1977 # Some non-ascii characters with defined case mappings 4925591369Sdanielk1977 # 5025591369Sdanielk1977 set ::EGRAVE "\xC8" 5125591369Sdanielk1977 set ::egrave "\xE8" 5225591369Sdanielk1977 5325591369Sdanielk1977 set ::OGRAVE "\xD2" 5425591369Sdanielk1977 set ::ograve "\xF2" 5525591369Sdanielk1977 5625591369Sdanielk1977 # That German letter that looks a bit like a B. The 5725591369Sdanielk1977 # upper-case version of which is "SS" (two characters). 5825591369Sdanielk1977 # 5925591369Sdanielk1977 set ::szlig "\xDF" 6025591369Sdanielk1977 6125591369Sdanielk1977 # Tests of the upper()/lower() functions. 6225591369Sdanielk1977 # 6325591369Sdanielk1977 test_expr icu-2.1 {i1='HellO WorlD'} {upper(i1)} {HELLO WORLD} 6425591369Sdanielk1977 test_expr icu-2.2 {i1='HellO WorlD'} {lower(i1)} {hello world} 6525591369Sdanielk1977 test_expr icu-2.3 {i1=$::egrave} {lower(i1)} $::egrave 6625591369Sdanielk1977 test_expr icu-2.4 {i1=$::egrave} {upper(i1)} $::EGRAVE 6725591369Sdanielk1977 test_expr icu-2.5 {i1=$::ograve} {lower(i1)} $::ograve 6825591369Sdanielk1977 test_expr icu-2.6 {i1=$::ograve} {upper(i1)} $::OGRAVE 6925591369Sdanielk1977 test_expr icu-2.3 {i1=$::EGRAVE} {lower(i1)} $::egrave 7025591369Sdanielk1977 test_expr icu-2.4 {i1=$::EGRAVE} {upper(i1)} $::EGRAVE 7125591369Sdanielk1977 test_expr icu-2.5 {i1=$::OGRAVE} {lower(i1)} $::ograve 7225591369Sdanielk1977 test_expr icu-2.6 {i1=$::OGRAVE} {upper(i1)} $::OGRAVE 7325591369Sdanielk1977 7425591369Sdanielk1977 test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS" 7525591369Sdanielk1977 test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss" 7625591369Sdanielk1977 7788a16508Sdrh do_execsql_test icu-2.9 { 7888a16508Sdrh SELECT upper(char(0xfb04,0xfb04,0xfb04,0xfb04)); 7988a16508Sdrh } {FFLFFLFFLFFL} 8088a16508Sdrh 8125591369Sdanielk1977 # In turkish (locale="tr_TR"), the lower case version of I 8225591369Sdanielk1977 # is "small dotless i" (code point 0x131 (decimal 305)). 8325591369Sdanielk1977 # 8425591369Sdanielk1977 set ::small_dotless_i "\u0131" 8525591369Sdanielk1977 test_expr icu-3.1 {i1='I'} {lower(i1)} "i" 8625591369Sdanielk1977 test_expr icu-3.2 {i1='I'} {lower(i1, 'tr_tr')} $::small_dotless_i 8725591369Sdanielk1977 test_expr icu-3.3 {i1='I'} {lower(i1, 'en_AU')} "i" 8821540ae4Sdan} 8925591369Sdanielk1977 9025591369Sdanielk1977#-------------------------------------------------------------------- 9125591369Sdanielk1977# Test the collation sequence function. 9225591369Sdanielk1977# 9325591369Sdanielk1977do_test icu-4.1 { 9425591369Sdanielk1977 execsql { 9525591369Sdanielk1977 CREATE TABLE fruit(name); 9625591369Sdanielk1977 INSERT INTO fruit VALUES('plum'); 9725591369Sdanielk1977 INSERT INTO fruit VALUES('cherry'); 9825591369Sdanielk1977 INSERT INTO fruit VALUES('apricot'); 9925591369Sdanielk1977 INSERT INTO fruit VALUES('peach'); 10025591369Sdanielk1977 INSERT INTO fruit VALUES('chokecherry'); 10125591369Sdanielk1977 INSERT INTO fruit VALUES('yamot'); 10225591369Sdanielk1977 } 10325591369Sdanielk1977} {} 10425591369Sdanielk1977do_test icu-4.2 { 10525591369Sdanielk1977 execsql { 10625591369Sdanielk1977 SELECT icu_load_collation('en_US', 'AmericanEnglish'); 10725591369Sdanielk1977 SELECT icu_load_collation('lt_LT', 'Lithuanian'); 10825591369Sdanielk1977 } 10925591369Sdanielk1977 execsql { 11025591369Sdanielk1977 SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC; 11125591369Sdanielk1977 } 11225591369Sdanielk1977} {apricot cherry chokecherry peach plum yamot} 11325591369Sdanielk1977 11425591369Sdanielk1977 11525591369Sdanielk1977# Test collation using Lithuanian rules. In the Lithuanian 11625591369Sdanielk1977# alphabet, "y" comes right after "i". 11725591369Sdanielk1977# 11825591369Sdanielk1977do_test icu-4.3 { 11925591369Sdanielk1977 execsql { 12025591369Sdanielk1977 SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC; 12125591369Sdanielk1977 } 12225591369Sdanielk1977} {apricot cherry chokecherry yamot peach plum} 12325591369Sdanielk1977 1243843a4c1Sdan#------------------------------------------------------------------------- 1253843a4c1Sdan# Test that it is not possible to call the ICU regex() function with 1263843a4c1Sdan# anything other than exactly two arguments. See also: 1273843a4c1Sdan# 1283843a4c1Sdan# http://src.chromium.org/viewvc/chrome/trunk/src/third_party/sqlite/icu-regexp.patch?revision=34807&view=markup 1293843a4c1Sdan# 13021540ae4Sdanifcapable icu { 1313843a4c1Sdan do_catchsql_test icu-5.1 { SELECT regexp('a[abc]c.*', 'abc') } {0 1} 1323843a4c1Sdan do_catchsql_test icu-5.2 { 1333843a4c1Sdan SELECT regexp('a[abc]c.*') 1343843a4c1Sdan } {1 {wrong number of arguments to function regexp()}} 1353843a4c1Sdan do_catchsql_test icu-5.3 { 1363843a4c1Sdan SELECT regexp('a[abc]c.*', 'abc', 'c') 1373843a4c1Sdan } {1 {wrong number of arguments to function regexp()}} 1383843a4c1Sdan do_catchsql_test icu-5.4 { 1393843a4c1Sdan SELECT 'abc' REGEXP 'a[abc]c.*' 1403843a4c1Sdan } {0 1} 1416116ee4eSdrh do_catchsql_test icu-5.5 {SELECT 'abc' REGEXP } {1 {incomplete input}} 1426116ee4eSdrh do_catchsql_test icu-5.6 {SELECT 'abc' REGEXP, 1} {1 {near ",": syntax error}} 1433843a4c1Sdan 14488a16508Sdrh do_malloc_test icu-6.10 -sqlbody { 14588a16508Sdrh SELECT upper(char(0xfb04,0xdf,0xfb04,0xe8,0xfb04)); 14688a16508Sdrh } 14721540ae4Sdan} 14888a16508Sdrh 149*589c7876Sdrh# 2020-03-19 150*589c7876Sdrh# The ESCAPE clause on LIKE takes precedence over wildcards 151*589c7876Sdrh# 152*589c7876Sdrhdo_execsql_test idu-6.0 { 153*589c7876Sdrh DROP TABLE IF EXISTS t1; 154*589c7876Sdrh CREATE TABLE t1(id INTEGER PRIMARY KEY, x TEXT); 155*589c7876Sdrh INSERT INTO t1 VALUES 156*589c7876Sdrh (1,'abcde'), 157*589c7876Sdrh (2,'abc_'), 158*589c7876Sdrh (3,'abc__'), 159*589c7876Sdrh (4,'abc%'), 160*589c7876Sdrh (5,'abc%%'); 161*589c7876Sdrh SELECT id FROM t1 WHERE x LIKE 'abc%%' ESCAPE '%'; 162*589c7876Sdrh} {4} 163*589c7876Sdrhdo_execsql_test icu-6.1 { 164*589c7876Sdrh SELECT id FROM t1 WHERE x LIKE 'abc__' ESCAPE '_'; 165*589c7876Sdrh} {2} 166*589c7876Sdrh 16725591369Sdanielk1977finish_test 168