regexp1.test 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # 2012 December 31
  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. # This file implements test for the REGEXP operator in test_regexp.c.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. do_test regexp1-1.1 {
  17. load_static_extension db regexp
  18. db eval {
  19. CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
  20. INSERT INTO t1 VALUES(1, 'For since by man came death,');
  21. INSERT INTO t1 VALUES(2, 'by man came also the resurrection of the dead.');
  22. INSERT INTO t1 VALUES(3, 'For as in Adam all die,');
  23. INSERT INTO t1 VALUES(4, 'even so in Christ shall all be made alive.');
  24. SELECT x FROM t1 WHERE y REGEXP '^For ' ORDER BY x;
  25. }
  26. } {1 3}
  27. do_execsql_test regexp1-1.2 {
  28. SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x;
  29. } {1 2 3 4}
  30. do_execsql_test regexp1-1.3 {
  31. SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x;
  32. } {1 2 4}
  33. do_execsql_test regexp1-1.4 {
  34. SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x;
  35. } {4}
  36. do_execsql_test regexp1-1.5 {
  37. SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x;
  38. } {4}
  39. do_execsql_test regexp1-1.6 {
  40. SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x;
  41. } {4}
  42. do_execsql_test regexp1-1.7 {
  43. SELECT x FROM t1 WHERE y REGEXP 'r{2}' ORDER BY x;
  44. } {2}
  45. do_execsql_test regexp1-1.8 {
  46. SELECT x FROM t1 WHERE y REGEXP 'r{3}' ORDER BY x;
  47. } {}
  48. do_execsql_test regexp1-1.9 {
  49. SELECT x FROM t1 WHERE y REGEXP 'r{1}' ORDER BY x;
  50. } {1 2 3 4}
  51. do_execsql_test regexp1-1.10 {
  52. SELECT x FROM t1 WHERE y REGEXP 'ur{2,10}e' ORDER BY x;
  53. } {2}
  54. do_execsql_test regexp1-1.11 {
  55. SELECT x FROM t1 WHERE y REGEXP '[Aa]dam' ORDER BY x;
  56. } {3}
  57. do_execsql_test regexp1-1.12 {
  58. SELECT x FROM t1 WHERE y REGEXP '[^Aa]dam' ORDER BY x;
  59. } {}
  60. do_execsql_test regexp1-1.13 {
  61. SELECT x FROM t1 WHERE y REGEXP '[^b-zB-Z]dam' ORDER BY x;
  62. } {3}
  63. do_execsql_test regexp1-1.14 {
  64. SELECT x FROM t1 WHERE y REGEXP 'alive' ORDER BY x;
  65. } {4}
  66. do_execsql_test regexp1-1.15 {
  67. SELECT x FROM t1 WHERE y REGEXP '^alive' ORDER BY x;
  68. } {}
  69. do_execsql_test regexp1-1.16 {
  70. SELECT x FROM t1 WHERE y REGEXP 'alive$' ORDER BY x;
  71. } {}
  72. do_execsql_test regexp1-1.17 {
  73. SELECT x FROM t1 WHERE y REGEXP 'alive.$' ORDER BY x;
  74. } {4}
  75. do_execsql_test regexp1-1.18 {
  76. SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x;
  77. } {4}
  78. do_execsql_test regexp1-1.19 {
  79. SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x;
  80. } {1 2 4}
  81. do_execsql_test regexp1-1.20 {
  82. SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x;
  83. } {1 2 4}
  84. do_execsql_test regexp1-1.21 {
  85. SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x;
  86. } {1 2}
  87. do_execsql_test regexp1-1.22 {
  88. SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x;
  89. } {1 2 4}
  90. do_execsql_test regexp1-1.23 {
  91. SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x;
  92. } {}
  93. do_execsql_test regexp1-1.24 {
  94. SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x;
  95. } {1 2 4}
  96. do_execsql_test regexp1-1.25 {
  97. SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x;
  98. } {}
  99. do_execsql_test regexp1-1.26 {
  100. SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x;
  101. } {4}
  102. do_execsql_test regexp1-1.27 {
  103. SELECT x FROM t1 WHERE y REGEXP
  104. '\b(unto|us|son|given|his|name|called|' ||
  105. 'wonderful|councelor|mighty|god|everlasting|father|' ||
  106. 'prince|peace|alive)\b';
  107. } {4}
  108. do_execsql_test regexp1-2.1 {
  109. SELECT 'aaaabbbbcccc' REGEXP 'ab*c',
  110. 'aaaacccc' REGEXP 'ab*c';
  111. } {1 1}
  112. do_execsql_test regexp1-2.2 {
  113. SELECT 'aaaabbbbcccc' REGEXP 'ab+c',
  114. 'aaaacccc' REGEXP 'ab+c';
  115. } {1 0}
  116. do_execsql_test regexp1-2.3 {
  117. SELECT 'aaaabbbbcccc' REGEXP 'ab?c',
  118. 'aaaacccc' REGEXP 'ab?c';
  119. } {0 1}
  120. do_execsql_test regexp1-2.4 {
  121. SELECT 'aaaabbbbbbcccc' REGEXP 'ab{3,5}c',
  122. 'aaaabbbbbcccc' REGEXP 'ab{3,5}c',
  123. 'aaaabbbbcccc' REGEXP 'ab{3,5}c',
  124. 'aaaabbbcccc' REGEXP 'ab{3,5}c',
  125. 'aaaabbcccc' REGEXP 'ab{3,5}c',
  126. 'aaaabcccc' REGEXP 'ab{3,5}c'
  127. } {0 1 1 1 0 0}
  128. do_execsql_test regexp1-2.5 {
  129. SELECT 'aaaabbbbcccc' REGEXP 'a(a|b|c)+c',
  130. 'aaaabbbbcccc' REGEXP '^a(a|b|c){11}c$',
  131. 'aaaabbbbcccc' REGEXP '^a(a|b|c){10}c$',
  132. 'aaaabbbbcccc' REGEXP '^a(a|b|c){9}c$'
  133. } {1 0 1 0}
  134. do_execsql_test regexp1-2.6 {
  135. SELECT 'aaaabbbbcccc' REGEXP '^a(a|bb|c)+c$',
  136. 'aaaabbbbcccc' REGEXP '^a(a|bbb|c)+c$',
  137. 'aaaabbbbcccc' REGEXP '^a(a|bbbb|c)+c$'
  138. } {1 0 1}
  139. do_execsql_test regexp1-2.7 {
  140. SELECT 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){3}c$',
  141. 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){4}c$',
  142. 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){5}c$'
  143. } {0 1 1}
  144. do_execsql_test regexp1-2.8 {
  145. SELECT 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c.d',
  146. 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c\*d',
  147. 'abc*def+ghi.jkl[mno]pqr' REGEXP 'f\+g',
  148. 'abc*def+ghi.jkl[mno]pqr' REGEXP 'i\.j',
  149. 'abc*def+ghi.jkl[mno]pqr' REGEXP 'l\[mno\]p'
  150. } {1 1 1 1 1}
  151. do_test regexp1-2.9 {
  152. set v1 "abc\ndef"
  153. db eval {SELECT $v1 REGEXP '^abc\ndef$'}
  154. } {1}
  155. do_test regexp1-2.10 {
  156. set v1 "abc\adef"
  157. db eval {SELECT $v1 REGEXP '^abc\adef$'}
  158. } {1}
  159. do_test regexp1-2.11 {
  160. set v1 "abc\tdef"
  161. db eval {SELECT $v1 REGEXP '^abc\tdef$'}
  162. } {1}
  163. do_test regexp1-2.12 {
  164. set v1 "abc\rdef"
  165. db eval {SELECT $v1 REGEXP '^abc\rdef$'}
  166. } {1}
  167. do_test regexp1-2.13 {
  168. set v1 "abc\fdef"
  169. db eval {SELECT $v1 REGEXP '^abc\fdef$'}
  170. } {1}
  171. do_test regexp1-2.14 {
  172. set v1 "abc\vdef"
  173. db eval {SELECT $v1 REGEXP '^abc\vdef$'}
  174. } {1}
  175. do_execsql_test regexp1-2.15 {
  176. SELECT 'abc\def' REGEXP '^abc\\def',
  177. 'abc(def' REGEXP '^abc\(def',
  178. 'abc)def' REGEXP '^abc\)def',
  179. 'abc*def' REGEXP '^abc\*def',
  180. 'abc.def' REGEXP '^abc\.def',
  181. 'abc+def' REGEXP '^abc\+def',
  182. 'abc?def' REGEXP '^abc\?def',
  183. 'abc[def' REGEXP '^abc\[def',
  184. 'abc$def' REGEXP '^abc\$',
  185. '^def' REGEXP '\^def',
  186. 'abc{4}x' REGEXP '^abc\{4\}x$',
  187. 'abc|def' REGEXP '^abc\|def$'
  188. } {1 1 1 1 1 1 1 1 1 1 1 1}
  189. do_execsql_test regexp1-2.20 {
  190. SELECT 'abc$¢€xyz' REGEXP '^abc\u0024\u00a2\u20acxyz$',
  191. 'abc$¢€xyz' REGEXP '^abc\u0024\u00A2\u20ACxyz$',
  192. 'abc$¢€xyz' REGEXP '^abc\x24\xa2\u20acxyz$'
  193. } {1 1 1}
  194. do_execsql_test regexp1-2.21 {
  195. SELECT 'abc$¢€xyz' REGEXP '^abc[\u0024][\u00a2][\u20ac]xyz$',
  196. 'abc$¢€xyz' REGEXP '^abc[\u0024\u00A2\u20AC]{3}xyz$',
  197. 'abc$¢€xyz' REGEXP '^abc[\x24][\xa2\u20ac]+xyz$'
  198. } {1 1 1}
  199. do_execsql_test regexp1-2.22 {
  200. SELECT 'abc$¢€xyz' REGEXP '^abc[^\u0025-X][^ -\u007f][^\u20ab]xyz$'
  201. } {1}
  202. finish_test