125 lines
3.2 KiB
Plaintext
125 lines
3.2 KiB
Plaintext
|
# 2014 Dec 20
|
||
|
#
|
||
|
# The author disclaims copyright to this source code. In place of
|
||
|
# a legal notice, here is a blessing:
|
||
|
#
|
||
|
# May you do good and not evil.
|
||
|
# May you find forgiveness for yourself and forgive others.
|
||
|
# May you share freely, never taking more than you give.
|
||
|
#
|
||
|
#***********************************************************************
|
||
|
#
|
||
|
# Tests of the scalar fts5_rowid() and fts5_decode() functions.
|
||
|
#
|
||
|
|
||
|
source [file join [file dirname [info script]] fts5_common.tcl]
|
||
|
set testprefix fts5rowid
|
||
|
|
||
|
do_catchsql_test 1.1 {
|
||
|
SELECT fts5_rowid()
|
||
|
} {1 {should be: fts5_rowid(subject, ....)}}
|
||
|
|
||
|
do_catchsql_test 1.2 {
|
||
|
SELECT fts5_rowid('segment')
|
||
|
} {1 {should be: fts5_rowid('segment', idx, segid, height, pgno))}}
|
||
|
|
||
|
do_execsql_test 1.3 {
|
||
|
SELECT fts5_rowid('segment', 1, 1, 1, 1)
|
||
|
} {4503670494330881}
|
||
|
|
||
|
do_catchsql_test 1.4 {
|
||
|
SELECT fts5_rowid('start-of-index');
|
||
|
} {1 {should be: fts5_rowid('start-of-index', idx)}}
|
||
|
|
||
|
do_execsql_test 1.5 {
|
||
|
SELECT fts5_rowid('start-of-index', 1);
|
||
|
} {4503668346847232}
|
||
|
|
||
|
do_catchsql_test 1.4 {
|
||
|
SELECT fts5_rowid('nosucharg');
|
||
|
} {1 {first arg to fts5_rowid() must be 'segment' or 'start-of-index'}}
|
||
|
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
# Tests of the fts5_decode() function.
|
||
|
#
|
||
|
reset_db
|
||
|
do_execsql_test 2.1 {
|
||
|
CREATE VIRTUAL TABLE x1 USING fts5(a, b);
|
||
|
INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
|
||
|
} {}
|
||
|
|
||
|
proc rnddoc {n} {
|
||
|
set map [list 0 a 1 b 2 c 3 d 4 e 5 f 6 g 7 h 8 i 9 j]
|
||
|
set doc [list]
|
||
|
for {set i 0} {$i < $n} {incr i} {
|
||
|
lappend doc [string map $map [format %.3d [expr int(rand()*100)]]]
|
||
|
}
|
||
|
set doc
|
||
|
}
|
||
|
db func rnddoc rnddoc
|
||
|
|
||
|
do_execsql_test 2.2 {
|
||
|
WITH r(a, b) AS (
|
||
|
SELECT rnddoc(6), rnddoc(6) UNION ALL
|
||
|
SELECT rnddoc(6), rnddoc(6) FROM r
|
||
|
)
|
||
|
INSERT INTO x1 SELECT * FROM r LIMIT 10000;
|
||
|
}
|
||
|
|
||
|
set res [db one {SELECT count(*) FROM x1_data}]
|
||
|
do_execsql_test 2.3 {
|
||
|
SELECT count(fts5_decode(rowid, block)) FROM x1_data;
|
||
|
} $res
|
||
|
do_execsql_test 2.4 {
|
||
|
UPDATE x1_data SET block = X'';
|
||
|
SELECT count(fts5_decode(rowid, block)) FROM x1_data;
|
||
|
} $res
|
||
|
|
||
|
do_execsql_test 2.5 {
|
||
|
INSERT INTO x1(x1, rank) VALUES('pgsz', 1024);
|
||
|
INSERT INTO x1(x1) VALUES('rebuild');
|
||
|
}
|
||
|
|
||
|
set res [db one {SELECT count(*) FROM x1_data}]
|
||
|
do_execsql_test 2.6 {
|
||
|
SELECT count(fts5_decode(rowid, block)) FROM x1_data;
|
||
|
} $res
|
||
|
do_execsql_test 2.7 {
|
||
|
UPDATE x1_data SET block = X'';
|
||
|
SELECT count(fts5_decode(rowid, block)) FROM x1_data;
|
||
|
} $res
|
||
|
|
||
|
#-------------------------------------------------------------------------
|
||
|
# Tests with very large tokens.
|
||
|
#
|
||
|
set strlist [list \
|
||
|
"[string repeat x 400]" \
|
||
|
"[string repeat x 300][string repeat w 100]" \
|
||
|
"[string repeat x 300][string repeat y 100]" \
|
||
|
"[string repeat x 300][string repeat z 600]" \
|
||
|
]
|
||
|
do_test 3.0 {
|
||
|
execsql {
|
||
|
BEGIN;
|
||
|
CREATE VIRTUAL TABLE x2 USING fts5(a);
|
||
|
}
|
||
|
foreach str $strlist { execsql { INSERT INTO x2 VALUES($str) } }
|
||
|
execsql COMMIT
|
||
|
} {}
|
||
|
|
||
|
for {set tn 0} {$tn<[llength $strlist]} {incr tn} {
|
||
|
set str [lindex $strlist $tn]
|
||
|
do_execsql_test 3.1.$tn {
|
||
|
SELECT rowid FROM x2 WHERE x2 MATCH $str
|
||
|
} [expr $tn+1]
|
||
|
}
|
||
|
|
||
|
set res [db one {SELECT count(*) FROM x2_data}]
|
||
|
do_execsql_test 3.2 {
|
||
|
SELECT count(fts5_decode(rowid, block)) FROM x2_data;
|
||
|
} $res
|
||
|
|
||
|
finish_test
|
||
|
|