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