3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file implements test for the REGEXP operator in test_regexp.c.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
19 load_static_extension db regexp
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.');
27 SELECT x FROM t1 WHERE y REGEXP '^For ' ORDER BY x;
31 do_execsql_test regexp1-1.2 {
32 SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x;
34 do_execsql_test regexp1-1.3 {
35 SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x;
37 do_execsql_test regexp1-1.4 {
38 SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x;
40 do_execsql_test regexp1-1.5 {
41 SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x;
43 do_execsql_test regexp1-1.6 {
44 SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x;
46 do_execsql_test regexp1-1.7 {
47 SELECT x FROM t1 WHERE y REGEXP 'r{2}' ORDER BY x;
49 do_execsql_test regexp1-1.8 {
50 SELECT x FROM t1 WHERE y REGEXP 'r{3}' ORDER BY x;
52 do_execsql_test regexp1-1.9 {
53 SELECT x FROM t1 WHERE y REGEXP 'r{1}' ORDER BY x;
55 do_execsql_test regexp1-1.10 {
56 SELECT x FROM t1 WHERE y REGEXP 'ur{2,10}e' ORDER BY x;
58 do_execsql_test regexp1-1.11 {
59 SELECT x FROM t1 WHERE y REGEXP '[Aa]dam' ORDER BY x;
61 do_execsql_test regexp1-1.12 {
62 SELECT x FROM t1 WHERE y REGEXP '[^Aa]dam' ORDER BY x;
64 do_execsql_test regexp1-1.13 {
65 SELECT x FROM t1 WHERE y REGEXP '[^b-zB-Z]dam' ORDER BY x;
67 do_execsql_test regexp1-1.14 {
68 SELECT x FROM t1 WHERE y REGEXP 'alive' ORDER BY x;
70 do_execsql_test regexp1-1.15 {
71 SELECT x FROM t1 WHERE y REGEXP '^alive' ORDER BY x;
73 do_execsql_test regexp1-1.16 {
74 SELECT x FROM t1 WHERE y REGEXP 'alive$' ORDER BY x;
76 do_execsql_test regexp1-1.17 {
77 SELECT x FROM t1 WHERE y REGEXP 'alive.$' ORDER BY x;
79 do_execsql_test regexp1-1.18 {
80 SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x;
82 do_execsql_test regexp1-1.19 {
83 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x;
85 do_execsql_test regexp1-1.20 {
86 SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x;
88 do_execsql_test regexp1-1.21 {
89 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x;
91 do_execsql_test regexp1-1.22 {
92 SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x;
94 do_execsql_test regexp1-1.23 {
95 SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x;
97 do_execsql_test regexp1-1.24 {
98 SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x;
100 do_execsql_test regexp1-1.25 {
101 SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x;
103 do_execsql_test regexp1-1.26 {
104 SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x;
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';
113 do_execsql_test regexp1-2.1 {
114 SELECT 'aaaabbbbcccc' REGEXP 'ab*c',
115 'aaaacccc' REGEXP 'ab*c';
117 do_execsql_test regexp1-2.2 {
118 SELECT 'aaaabbbbcccc' REGEXP 'ab+c',
119 'aaaacccc' REGEXP 'ab+c';
121 do_execsql_test regexp1-2.3 {
122 SELECT 'aaaabbbbcccc' REGEXP 'ab?c',
123 'aaaacccc' REGEXP 'ab?c';
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'
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$'
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$'
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$'
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'
158 do_test regexp1-2.9 {
160 db eval {SELECT $v1 REGEXP '^abc\ndef$'}
162 do_test regexp1-2.10 {
164 db eval {SELECT $v1 REGEXP '^abc\adef$'}
166 do_test regexp1-2.11 {
168 db eval {SELECT $v1 REGEXP '^abc\tdef$'}
170 do_test regexp1-2.12 {
172 db eval {SELECT $v1 REGEXP '^abc\rdef$'}
174 do_test regexp1-2.13 {
176 db eval {SELECT $v1 REGEXP '^abc\fdef$'}
178 do_test regexp1-2.14 {
180 db eval {SELECT $v1 REGEXP '^abc\vdef$'}
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}
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$'
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$'
207 do_execsql_test regexp1-2.22 {
208 SELECT 'abc$¢€xyz' REGEXP '^abc[^\u0025-X][^ -\u007f][^\u20ab]xyz$'