More test cases for the REGEXP operator. Fix minor bugs uncovered by these

test cases.

FossilOrigin-Name: a611c75061c8e821cb266fcb09759100d4a646b0
This commit is contained in:
drh 2012-12-31 20:16:35 +00:00
parent 14172743a2
commit 25846af3be
5 changed files with 142 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Add\sthe\stest_regexp.c\smodule\scontaining\sa\scross-platform\simplementation\s\nof\sthe\sREGEXP\soperator.
D 2012-12-31T19:18:38.256
C More\stest\scases\sfor\sthe\sREGEXP\soperator.\s\sFix\sminor\sbugs\suncovered\sby\sthese\ntest\scases.
D 2012-12-31T20:16:35.189
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -175,7 +175,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
F src/resolve.c 52331299f4095397d6d00715b70cd153baa11931
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
F src/select.c 5eab6941c0ac97355817f846b77cd20bfdf5a82e
F src/shell.c e6525781d27a84f1b74586831b6ad8472a8c8dc6
F src/shell.c 11c9611580bb2ffce3a232f31f7f8cc310df0843
F src/sqlite.h.in 39cc33bb08897c748fe3383c29ccf56585704177
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477
@ -217,7 +217,7 @@ F src/test_osinst.c 90a845c8183013d80eccb1f29e8805608516edba
F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00
F src/test_quota.c 0e0e2e3bf6766b101ecccd8c042b66e44e9be8f5
F src/test_quota.h 8761e463b25e75ebc078bd67d70e39b9c817a0cb
F src/test_regexp.c c24ae2a0de64eb9dfa1dd77b77448b1d794cd395
F src/test_regexp.c d8cb342e08a346a6daeda29e434e2d9a49f557ec
F src/test_rtree.c aba603c949766c4193f1068b91c787f57274e0d9
F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
F src/test_server.c 2f99eb2837dfa06a4aacf24af24c6affdf66a84f
@ -667,7 +667,7 @@ F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459
F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df
F test/rdonly.test c267d050a1d9a6a321de502b737daf28821a518d
F test/regexp1.test 38da302b75504dd8b960c8f06968ddf8039777ad
F test/regexp1.test bbcb74e1bbdc20a7c0b9b2360deda14c4df1b46a
F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a
F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce
@ -1030,7 +1030,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P ff6857b6ed6a46671006b75157d8cf853a816ef9
R 2e582c43743655b03da399d168172dad
P 46c8c01b751c1ea7fc02cc35e3b5bb99dbe46c4b
R 6e56302eb044cc0fb37d40997bea4520
U drh
Z c7b82d9d758f8f0ccceb37ea12601a6d
Z d62b4f1d3e09d5165b99ff6799092c00

View File

@ -1 +1 @@
46c8c01b751c1ea7fc02cc35e3b5bb99dbe46c4b
a611c75061c8e821cb266fcb09759100d4a646b0

View File

@ -1482,7 +1482,7 @@ static void open_db(struct callback_data *p){
#endif
#ifdef SQLITE_ENABLE_REGEXP
{
extern sqlite3_add_regexp_func(sqlite3*);
extern int sqlite3_add_regexp_func(sqlite3*);
sqlite3_add_regexp_func(db);
}
#endif

View File

@ -342,13 +342,13 @@ static int re_hex(int c, int *pV){
if( c>='0' && c<='9' ){
c -= '0';
}else if( c>='a' && c<='f' ){
c -= 'a' + 10;
c -= 'a' - 10;
}else if( c>='A' && c<='F' ){
c -= 'A' + 10;
c -= 'A' - 10;
}else{
return 0;
}
*pV = (*pV)*16 + c;
*pV = (*pV)*16 + (c & 0xff);
return 1;
}
@ -356,7 +356,7 @@ static int re_hex(int c, int *pV){
** return its intepretation.
*/
static unsigned re_esc_char(ReCompiled *p){
static const char zEsc[] = "afnrtv\\()*.+?[$^{|";
static const char zEsc[] = "afnrtv\\()*.+?[$^{|}]";
static const char zTrans[] = "\a\f\n\r\t\v";
int i, v = 0;
char c = p->zIn[0];
@ -381,7 +381,7 @@ static unsigned re_esc_char(ReCompiled *p){
}
for(i=0; zEsc[i] && zEsc[i]!=c; i++){}
if( zEsc[i] ){
if( c<6 ) c = zTrans[i];
if( i<6 ) c = zTrans[i];
p->zIn++;
}else{
p->zErr = "unknown \\ escape";

View File

@ -79,6 +79,133 @@ do_execsql_test regexp1-1.17 {
do_execsql_test regexp1-1.18 {
SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x;
} {4}
do_execsql_test regexp1-1.19 {
SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x;
} {1 2 4}
do_execsql_test regexp1-1.20 {
SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x;
} {1 2 4}
do_execsql_test regexp1-1.21 {
SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x;
} {1 2}
do_execsql_test regexp1-1.22 {
SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x;
} {1 2 4}
do_execsql_test regexp1-1.23 {
SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x;
} {}
do_execsql_test regexp1-1.24 {
SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x;
} {1 2 4}
do_execsql_test regexp1-1.25 {
SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x;
} {}
do_execsql_test regexp1-1.26 {
SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x;
} {4}
do_execsql_test regexp1-1.27 {
SELECT x FROM t1 WHERE y REGEXP
'\b(unto|us|son|given|his|name|called|' ||
'wonderful|councelor|mighty|god|everlasting|father|' ||
'prince|peace|alive)\b';
} {4}
do_execsql_test regexp1-2.1 {
SELECT 'aaaabbbbcccc' REGEXP 'ab*c',
'aaaacccc' REGEXP 'ab*c';
} {1 1}
do_execsql_test regexp1-2.2 {
SELECT 'aaaabbbbcccc' REGEXP 'ab+c',
'aaaacccc' REGEXP 'ab+c';
} {1 0}
do_execsql_test regexp1-2.3 {
SELECT 'aaaabbbbcccc' REGEXP 'ab?c',
'aaaacccc' REGEXP 'ab?c';
} {0 1}
do_execsql_test regexp1-2.4 {
SELECT 'aaaabbbbbbcccc' REGEXP 'ab{3,5}c',
'aaaabbbbbcccc' REGEXP 'ab{3,5}c',
'aaaabbbbcccc' REGEXP 'ab{3,5}c',
'aaaabbbcccc' REGEXP 'ab{3,5}c',
'aaaabbcccc' REGEXP 'ab{3,5}c',
'aaaabcccc' REGEXP 'ab{3,5}c'
} {0 1 1 1 0 0}
do_execsql_test regexp1-2.5 {
SELECT 'aaaabbbbcccc' REGEXP 'a(a|b|c)+c',
'aaaabbbbcccc' REGEXP '^a(a|b|c){11}c$',
'aaaabbbbcccc' REGEXP '^a(a|b|c){10}c$',
'aaaabbbbcccc' REGEXP '^a(a|b|c){9}c$'
} {1 0 1 0}
do_execsql_test regexp1-2.6 {
SELECT 'aaaabbbbcccc' REGEXP '^a(a|bb|c)+c$',
'aaaabbbbcccc' REGEXP '^a(a|bbb|c)+c$',
'aaaabbbbcccc' REGEXP '^a(a|bbbb|c)+c$'
} {1 0 1}
do_execsql_test regexp1-2.7 {
SELECT 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){3}c$',
'aaaabbbbcccc' REGEXP '^a([ac]+|bb){4}c$',
'aaaabbbbcccc' REGEXP '^a([ac]+|bb){5}c$'
} {0 1 1}
do_execsql_test regexp1-2.8 {
SELECT 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c.d',
'abc*def+ghi.jkl[mno]pqr' REGEXP 'c\*d',
'abc*def+ghi.jkl[mno]pqr' REGEXP 'f\+g',
'abc*def+ghi.jkl[mno]pqr' REGEXP 'i\.j',
'abc*def+ghi.jkl[mno]pqr' REGEXP 'l\[mno\]p'
} {1 1 1 1 1}
do_test regexp1-2.9 {
set v1 "abc\ndef"
db eval {SELECT $v1 REGEXP '^abc\ndef$'}
} {1}
do_test regexp1-2.10 {
set v1 "abc\adef"
db eval {SELECT $v1 REGEXP '^abc\adef$'}
} {1}
do_test regexp1-2.11 {
set v1 "abc\tdef"
db eval {SELECT $v1 REGEXP '^abc\tdef$'}
} {1}
do_test regexp1-2.12 {
set v1 "abc\rdef"
db eval {SELECT $v1 REGEXP '^abc\rdef$'}
} {1}
do_test regexp1-2.13 {
set v1 "abc\fdef"
db eval {SELECT $v1 REGEXP '^abc\fdef$'}
} {1}
do_test regexp1-2.14 {
set v1 "abc\vdef"
db eval {SELECT $v1 REGEXP '^abc\vdef$'}
} {1}
do_execsql_test regexp1-2.15 {
SELECT 'abc\def' REGEXP '^abc\\def',
'abc(def' REGEXP '^abc\(def',
'abc)def' REGEXP '^abc\)def',
'abc*def' REGEXP '^abc\*def',
'abc.def' REGEXP '^abc\.def',
'abc+def' REGEXP '^abc\+def',
'abc?def' REGEXP '^abc\?def',
'abc[def' REGEXP '^abc\[def',
'abc$def' REGEXP '^abc\$',
'^def' REGEXP '\^def',
'abc{4}x' REGEXP '^abc\{4\}x$',
'abc|def' REGEXP '^abc\|def$'
} {1 1 1 1 1 1 1 1 1 1 1 1}
do_execsql_test regexp1-2.20 {
SELECT 'abc$¢€xyz' REGEXP '^abc\u0024\u00a2\u20acxyz$',
'abc$¢€xyz' REGEXP '^abc\u0024\u00A2\u20ACxyz$',
'abc$¢€xyz' REGEXP '^abc\x24\xa2\x20acxyz$'
} {1 1 1}
do_execsql_test regexp1-2.21 {
SELECT 'abc$¢€xyz' REGEXP '^abc[\u0024][\u00a2][\u20ac]xyz$',
'abc$¢€xyz' REGEXP '^abc[\u0024\u00A2\u20AC]{3}xyz$',
'abc$¢€xyz' REGEXP '^abc[\x24][\xa2\x20ac]+xyz$'
} {1 1 1}
do_execsql_test regexp1-2.22 {
SELECT 'abc$¢€xyz' REGEXP '^abc[^\u0025-X][^ -\u007f][^\u20ab]xyz$'
} {1}
finish_test