Remove some unused code from fts3. Add tests to fts3matchinfo.test.
FossilOrigin-Name: ae40b34cf7c24c9601bdfb5cbe5b20f05a376ea8
This commit is contained in:
@@ -66,4 +66,141 @@ do_execsql_test 3.1 {
|
||||
SELECT mtchinfo FROM t3;
|
||||
} {{Beside the lake, beneath the trees}}
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Proc [do_matchinfo_test] is used to test the FTSX matchinfo() function.
|
||||
#
|
||||
# The first argument - $tn - is a test identifier. This may be either a
|
||||
# full identifier (i.e. "fts3matchinfo-1.1") or, if global var $testprefix
|
||||
# is set, just the numeric component (i.e. "1.1").
|
||||
#
|
||||
# The second argument is the name of an FTSX table. The third is the
|
||||
# full text of a WHERE/MATCH expression to query the table for
|
||||
# (i.e. "t1 MATCH 'abc'"). The final argument - $results - should be a
|
||||
# key-value list (serialized array) with matchinfo() format specifiers
|
||||
# as keys, and the results of executing the statement:
|
||||
#
|
||||
# SELECT matchinfo($tbl, '$key') FROM $tbl WHERE $expr
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# CREATE VIRTUAL TABLE t1 USING fts4;
|
||||
# INSERT INTO t1 VALUES('abc');
|
||||
# INSERT INTO t1 VALUES('def');
|
||||
# INSERT INTO t1 VALUES('abc abc');
|
||||
#
|
||||
# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" {
|
||||
# n {3 3}
|
||||
# p {1 1}
|
||||
# c {1 1}
|
||||
# x {{1 3 2} {2 3 2}}
|
||||
# }
|
||||
#
|
||||
# If the $results list contains keys mapped to "-" instead of a matchinfo()
|
||||
# result, then this command computes the expected results based on other
|
||||
# mappings to test the matchinfo() function. For example, the command above
|
||||
# could be changed to:
|
||||
#
|
||||
# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" {
|
||||
# n {3 3} p {1 1} c {1 1} x {{1 3 2} {2 3 2}}
|
||||
# pcx -
|
||||
# }
|
||||
#
|
||||
# And this command would compute the expected results for matchinfo(t1, 'pcx')
|
||||
# based on the results of matchinfo(t1, 'p'), matchinfo(t1, 'c') and
|
||||
# matchinfo(t1, 'x') in order to test 'pcx'.
|
||||
#
|
||||
proc do_matchinfo_test {tn tbl expr results} {
|
||||
|
||||
foreach {fmt res} $results {
|
||||
if {$res == "-"} continue
|
||||
set resarray($fmt) $res
|
||||
}
|
||||
|
||||
set nRow 0
|
||||
foreach {fmt res} [array get resarray] {
|
||||
if {[llength $res]>$nRow} { set nRow [llength $res] }
|
||||
}
|
||||
|
||||
# Construct expected results for any formats for which the caller
|
||||
# supplied result is "-".
|
||||
#
|
||||
foreach {fmt res} $results {
|
||||
if {$res == "-"} {
|
||||
set res [list]
|
||||
for {set iRow 0} {$iRow<$nRow} {incr iRow} {
|
||||
set rowres [list]
|
||||
foreach c [split $fmt ""] {
|
||||
set rowres [concat $rowres [lindex $resarray($c) $iRow]]
|
||||
}
|
||||
lappend res $rowres
|
||||
}
|
||||
set resarray($fmt) $res
|
||||
}
|
||||
}
|
||||
|
||||
# Test each matchinfo() request individually.
|
||||
#
|
||||
foreach {fmt res} [array get resarray] {
|
||||
set sql "SELECT mit(matchinfo($tbl, '$fmt')) FROM $tbl WHERE $expr"
|
||||
do_execsql_test $tn.$fmt $sql [normalize2 $res]
|
||||
}
|
||||
|
||||
# Test them all executed together (multiple invocations of matchinfo()).
|
||||
#
|
||||
set exprlist [list]
|
||||
foreach {format res} [array get resarray] {
|
||||
lappend exprlist "mit(matchinfo($tbl, '$format'))"
|
||||
}
|
||||
set allres [list]
|
||||
for {set iRow 0} {$iRow<$nRow} {incr iRow} {
|
||||
foreach {format res} [array get resarray] {
|
||||
lappend allres [lindex $res $iRow]
|
||||
}
|
||||
}
|
||||
set sql "SELECT [join $exprlist ,] FROM $tbl WHERE $expr"
|
||||
do_execsql_test $tn.multi $sql [normalize2 $allres]
|
||||
}
|
||||
proc normalize2 {list_of_lists} {
|
||||
set res [list]
|
||||
foreach elem $list_of_lists {
|
||||
lappend res [list {*}$elem]
|
||||
}
|
||||
return $res
|
||||
}
|
||||
|
||||
|
||||
do_execsql_test 4.1.0 {
|
||||
CREATE VIRTUAL TABLE t4 USING fts4(x, y);
|
||||
INSERT INTO t4 VALUES('a b c d e', 'f g h i j');
|
||||
INSERT INTO t4 VALUES('f g h i j', 'a b c d e');
|
||||
}
|
||||
do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} {
|
||||
p {3 3}
|
||||
c {2 2}
|
||||
x {
|
||||
{1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1}
|
||||
{0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1}
|
||||
}
|
||||
n {2 2}
|
||||
l {{5 5} {5 5}}
|
||||
a {{5 5} {5 5}}
|
||||
|
||||
xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc -
|
||||
}
|
||||
do_matchinfo_test 4.1.2 t4 {t4 MATCH '"g h i"'} {
|
||||
p {1 1}
|
||||
c {2 2}
|
||||
x {
|
||||
{0 1 1 1 1 1}
|
||||
{1 1 1 0 1 1}
|
||||
}
|
||||
n {2 2}
|
||||
l {{5 5} {5 5}}
|
||||
a {{5 5} {5 5}}
|
||||
|
||||
xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc -
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
Reference in New Issue
Block a user