icu.test 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # 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. #
  12. # $Id: icu.test,v 1.2 2008/07/12 14:52:20 drh Exp $
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. ifcapable !icu {
  17. finish_test
  18. return
  19. }
  20. # Create a table to work with.
  21. #
  22. execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)}
  23. execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')}
  24. proc test_expr {name settings expr result} {
  25. do_test $name [format {
  26. lindex [db eval {
  27. BEGIN;
  28. UPDATE test1 SET %s;
  29. SELECT %s FROM test1;
  30. ROLLBACK;
  31. }] 0
  32. } $settings $expr] $result
  33. }
  34. # Tests of the REGEXP operator.
  35. #
  36. test_expr icu-1.1 {i1='hello'} {i1 REGEXP 'hello'} 1
  37. test_expr icu-1.2 {i1='hello'} {i1 REGEXP '.ello'} 1
  38. test_expr icu-1.3 {i1='hello'} {i1 REGEXP '.ell'} 0
  39. test_expr icu-1.4 {i1='hello'} {i1 REGEXP '.ell.*'} 1
  40. test_expr icu-1.5 {i1=NULL} {i1 REGEXP '.ell.*'} {}
  41. # Some non-ascii characters with defined case mappings
  42. #
  43. set ::EGRAVE "\xC8"
  44. set ::egrave "\xE8"
  45. set ::OGRAVE "\xD2"
  46. set ::ograve "\xF2"
  47. # That German letter that looks a bit like a B. The
  48. # upper-case version of which is "SS" (two characters).
  49. #
  50. set ::szlig "\xDF"
  51. # Tests of the upper()/lower() functions.
  52. #
  53. test_expr icu-2.1 {i1='HellO WorlD'} {upper(i1)} {HELLO WORLD}
  54. test_expr icu-2.2 {i1='HellO WorlD'} {lower(i1)} {hello world}
  55. test_expr icu-2.3 {i1=$::egrave} {lower(i1)} $::egrave
  56. test_expr icu-2.4 {i1=$::egrave} {upper(i1)} $::EGRAVE
  57. test_expr icu-2.5 {i1=$::ograve} {lower(i1)} $::ograve
  58. test_expr icu-2.6 {i1=$::ograve} {upper(i1)} $::OGRAVE
  59. test_expr icu-2.3 {i1=$::EGRAVE} {lower(i1)} $::egrave
  60. test_expr icu-2.4 {i1=$::EGRAVE} {upper(i1)} $::EGRAVE
  61. test_expr icu-2.5 {i1=$::OGRAVE} {lower(i1)} $::ograve
  62. test_expr icu-2.6 {i1=$::OGRAVE} {upper(i1)} $::OGRAVE
  63. test_expr icu-2.7 {i1=$::szlig} {upper(i1)} "SS"
  64. test_expr icu-2.8 {i1='SS'} {lower(i1)} "ss"
  65. # In turkish (locale="tr_TR"), the lower case version of I
  66. # is "small dotless i" (code point 0x131 (decimal 305)).
  67. #
  68. set ::small_dotless_i "\u0131"
  69. test_expr icu-3.1 {i1='I'} {lower(i1)} "i"
  70. test_expr icu-3.2 {i1='I'} {lower(i1, 'tr_tr')} $::small_dotless_i
  71. test_expr icu-3.3 {i1='I'} {lower(i1, 'en_AU')} "i"
  72. #--------------------------------------------------------------------
  73. # Test the collation sequence function.
  74. #
  75. do_test icu-4.1 {
  76. execsql {
  77. CREATE TABLE fruit(name);
  78. INSERT INTO fruit VALUES('plum');
  79. INSERT INTO fruit VALUES('cherry');
  80. INSERT INTO fruit VALUES('apricot');
  81. INSERT INTO fruit VALUES('peach');
  82. INSERT INTO fruit VALUES('chokecherry');
  83. INSERT INTO fruit VALUES('yamot');
  84. }
  85. } {}
  86. do_test icu-4.2 {
  87. execsql {
  88. SELECT icu_load_collation('en_US', 'AmericanEnglish');
  89. SELECT icu_load_collation('lt_LT', 'Lithuanian');
  90. }
  91. execsql {
  92. SELECT name FROM fruit ORDER BY name COLLATE AmericanEnglish ASC;
  93. }
  94. } {apricot cherry chokecherry peach plum yamot}
  95. # Test collation using Lithuanian rules. In the Lithuanian
  96. # alphabet, "y" comes right after "i".
  97. #
  98. do_test icu-4.3 {
  99. execsql {
  100. SELECT name FROM fruit ORDER BY name COLLATE Lithuanian ASC;
  101. }
  102. } {apricot cherry chokecherry yamot peach plum}
  103. #-------------------------------------------------------------------------
  104. # Test that it is not possible to call the ICU regex() function with
  105. # anything other than exactly two arguments. See also:
  106. #
  107. # http://src.chromium.org/viewvc/chrome/trunk/src/third_party/sqlite/icu-regexp.patch?revision=34807&view=markup
  108. #
  109. do_catchsql_test icu-5.1 { SELECT regexp('a[abc]c.*', 'abc') } {0 1}
  110. do_catchsql_test icu-5.2 {
  111. SELECT regexp('a[abc]c.*')
  112. } {1 {wrong number of arguments to function regexp()}}
  113. do_catchsql_test icu-5.3 {
  114. SELECT regexp('a[abc]c.*', 'abc', 'c')
  115. } {1 {wrong number of arguments to function regexp()}}
  116. do_catchsql_test icu-5.4 {
  117. SELECT 'abc' REGEXP 'a[abc]c.*'
  118. } {0 1}
  119. do_catchsql_test icu-5.4 { SELECT 'abc' REGEXP } {1 {near " ": syntax error}}
  120. do_catchsql_test icu-5.5 { SELECT 'abc' REGEXP, 1 } {1 {near ",": syntax error}}
  121. finish_test