1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Add tests for the new MATCH operator. (CVS 3238)

FossilOrigin-Name: b4024c394d25e5a0abdb07be779ae41581834c42
This commit is contained in:
danielk1977
2006-06-14 08:48:25 +00:00
parent 47d0809401
commit 619a3693a2
4 changed files with 59 additions and 10 deletions

View File

@ -13,7 +13,7 @@
# in particular the optimizations that occur to help those operators
# run faster.
#
# $Id: like.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $
# $Id: like.test,v 1.5 2006/06/14 08:48:26 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -114,6 +114,23 @@ do_test like-2.2 {
}
} {abc abcd}
# Tests of the MATCH operator
#
do_test like-2.3 {
proc test_match {a b} {
return [string match $a $b]
}
db function match test_match
execsql {
SELECT x FROM t1 WHERE x MATCH '*abc*' ORDER BY 1;
}
} {{ABC abc xyz} abc abcd}
do_test like-2.4 {
execsql {
SELECT x FROM t1 WHERE x MATCH 'abc*' ORDER BY 1;
}
} {abc abcd}
# For the remaining tests, we need to have the like optimizations
# enabled.
#

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is creating and dropping virtual tables.
#
# $Id: vtab1.test,v 1.13 2006/06/14 07:41:32 danielk1977 Exp $
# $Id: vtab1.test,v 1.14 2006/06/14 08:48:26 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -321,6 +321,38 @@ do_test vtab1-3.13 {
} [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} \
xFilter {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 2 10 ]
# Add a function for the MATCH operator. Everything always matches!
proc test_match {lhs rhs} {
lappend ::echo_module MATCH $lhs $rhs
return 1
}
db function match test_match
set echo_module ""
do_test vtab1-3.12 {
set echo_module ""
execsql {
SELECT * FROM t1 WHERE a MATCH 'string';
}
} {1 2 3 4 5 6}
do_test vtab1-3.13 {
set echo_module
} [list xBestIndex {SELECT rowid, * FROM 'treal'} \
xFilter {SELECT rowid, * FROM 'treal'} \
MATCH string 1 \
MATCH string 4 \
]
do_test vtab1-3.14 {
set echo_module ""
execsql {
SELECT * FROM t1 WHERE b MATCH 'string';
}
} {1 2 3 4 5 6}
do_test vtab1-3.15 {
set echo_module
} [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b MATCH ?} \
xFilter {SELECT rowid, * FROM 'treal' WHERE b MATCH ?} string ]
#----------------------------------------------------------------------
# Test case vtab1-3 test table scans and the echo module's
# xBestIndex/xFilter handling of ORDER BY clauses.