blob: 0e63cd98c800973e79fe1dffd668c5b0fd4fbef5 [file] [log] [blame]
drh14172742012-12-31 19:18:38 +00001# 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
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18do_test regexp1-1.1 {
drh248f2be2013-04-23 20:10:13 +000019 load_static_extension db regexp
drh14172742012-12-31 19:18:38 +000020 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
31do_execsql_test regexp1-1.2 {
32 SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x;
33} {1 2 3 4}
34do_execsql_test regexp1-1.3 {
35 SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x;
36} {1 2 4}
37do_execsql_test regexp1-1.4 {
38 SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x;
39} {4}
40do_execsql_test regexp1-1.5 {
41 SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x;
42} {4}
43do_execsql_test regexp1-1.6 {
44 SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x;
45} {4}
46do_execsql_test regexp1-1.7 {
47 SELECT x FROM t1 WHERE y REGEXP 'r{2}' ORDER BY x;
48} {2}
49do_execsql_test regexp1-1.8 {
50 SELECT x FROM t1 WHERE y REGEXP 'r{3}' ORDER BY x;
51} {}
52do_execsql_test regexp1-1.9 {
53 SELECT x FROM t1 WHERE y REGEXP 'r{1}' ORDER BY x;
54} {1 2 3 4}
55do_execsql_test regexp1-1.10 {
56 SELECT x FROM t1 WHERE y REGEXP 'ur{2,10}e' ORDER BY x;
57} {2}
58do_execsql_test regexp1-1.11 {
59 SELECT x FROM t1 WHERE y REGEXP '[Aa]dam' ORDER BY x;
60} {3}
61do_execsql_test regexp1-1.12 {
62 SELECT x FROM t1 WHERE y REGEXP '[^Aa]dam' ORDER BY x;
63} {}
64do_execsql_test regexp1-1.13 {
65 SELECT x FROM t1 WHERE y REGEXP '[^b-zB-Z]dam' ORDER BY x;
66} {3}
67do_execsql_test regexp1-1.14 {
68 SELECT x FROM t1 WHERE y REGEXP 'alive' ORDER BY x;
69} {4}
70do_execsql_test regexp1-1.15 {
71 SELECT x FROM t1 WHERE y REGEXP '^alive' ORDER BY x;
72} {}
73do_execsql_test regexp1-1.16 {
74 SELECT x FROM t1 WHERE y REGEXP 'alive$' ORDER BY x;
75} {}
76do_execsql_test regexp1-1.17 {
77 SELECT x FROM t1 WHERE y REGEXP 'alive.$' ORDER BY x;
78} {4}
79do_execsql_test regexp1-1.18 {
80 SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x;
81} {4}
drh25846af2012-12-31 20:16:35 +000082do_execsql_test regexp1-1.19 {
83 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x;
84} {1 2 4}
85do_execsql_test regexp1-1.20 {
86 SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x;
87} {1 2 4}
88do_execsql_test regexp1-1.21 {
89 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x;
90} {1 2}
91do_execsql_test regexp1-1.22 {
92 SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x;
93} {1 2 4}
94do_execsql_test regexp1-1.23 {
95 SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x;
96} {}
97do_execsql_test regexp1-1.24 {
98 SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x;
99} {1 2 4}
100do_execsql_test regexp1-1.25 {
101 SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x;
102} {}
103do_execsql_test regexp1-1.26 {
104 SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x;
105} {4}
106do_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}
drh14172742012-12-31 19:18:38 +0000112
drh25846af2012-12-31 20:16:35 +0000113do_execsql_test regexp1-2.1 {
114 SELECT 'aaaabbbbcccc' REGEXP 'ab*c',
115 'aaaacccc' REGEXP 'ab*c';
116} {1 1}
117do_execsql_test regexp1-2.2 {
118 SELECT 'aaaabbbbcccc' REGEXP 'ab+c',
119 'aaaacccc' REGEXP 'ab+c';
120} {1 0}
121do_execsql_test regexp1-2.3 {
122 SELECT 'aaaabbbbcccc' REGEXP 'ab?c',
123 'aaaacccc' REGEXP 'ab?c';
124} {0 1}
125do_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}
133do_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}
139do_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}
144do_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
150do_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
158do_test regexp1-2.9 {
159 set v1 "abc\ndef"
160 db eval {SELECT $v1 REGEXP '^abc\ndef$'}
161} {1}
162do_test regexp1-2.10 {
163 set v1 "abc\adef"
164 db eval {SELECT $v1 REGEXP '^abc\adef$'}
165} {1}
166do_test regexp1-2.11 {
167 set v1 "abc\tdef"
168 db eval {SELECT $v1 REGEXP '^abc\tdef$'}
169} {1}
170do_test regexp1-2.12 {
171 set v1 "abc\rdef"
172 db eval {SELECT $v1 REGEXP '^abc\rdef$'}
173} {1}
174do_test regexp1-2.13 {
175 set v1 "abc\fdef"
176 db eval {SELECT $v1 REGEXP '^abc\fdef$'}
177} {1}
178do_test regexp1-2.14 {
179 set v1 "abc\vdef"
180 db eval {SELECT $v1 REGEXP '^abc\vdef$'}
181} {1}
182do_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
197do_execsql_test regexp1-2.20 {
198 SELECT 'abc$¢€xyz' REGEXP '^abc\u0024\u00a2\u20acxyz$',
199 'abc$¢€xyz' REGEXP '^abc\u0024\u00A2\u20ACxyz$',
drhb064dc32013-01-18 03:35:14 +0000200 'abc$¢€xyz' REGEXP '^abc\x24\xa2\u20acxyz$'
drh25846af2012-12-31 20:16:35 +0000201} {1 1 1}
202do_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$',
drhb064dc32013-01-18 03:35:14 +0000205 'abc$¢€xyz' REGEXP '^abc[\x24][\xa2\u20ac]+xyz$'
drh25846af2012-12-31 20:16:35 +0000206} {1 1 1}
207do_execsql_test regexp1-2.22 {
208 SELECT 'abc$¢€xyz' REGEXP '^abc[^\u0025-X][^ -\u007f][^\u20ab]xyz$'
209} {1}
drh14172742012-12-31 19:18:38 +0000210
211finish_test