CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
fts3al.test74 linesDownload Raw Back to test
1# 2007 March 282#3# The author disclaims copyright to this source code.4#5#*************************************************************************6# This file implements regression tests for SQLite library.  The focus7# of this script is testing isspace/isalnum/tolower problems with the8# FTS3 module.  Unfortunately, this code isn't a really principled set9# of tests, because it is impossible to know where new uses of these10# functions might appear.11#12# $Id: fts3al.test,v 1.2 2007/12/13 21:54:11 drh Exp $13#14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17 18# If SQLITE_ENABLE_FTS3 is defined, omit this file.19ifcapable !fts3 {20  finish_test21  return22}23 24# Tests that startsWith() (calls isspace, tolower, isalnum) can handle25# hi-bit chars.  parseSpec() also calls isalnum here.26do_test fts3al-1.1 {27  execsql "CREATE VIRTUAL TABLE t1 USING fts3(content, \x80)"28} {}29 30# Additionally tests isspace() call in getToken(), and isalnum() call31# in tokenListToIdList().32do_test fts3al-1.2 {33  catch {34    execsql "CREATE VIRTUAL TABLE t2 USING fts3(content, tokenize \x80)"35  }36  sqlite3_errmsg $DB37} "unknown tokenizer: \x80"38 39# Additionally test final isalnum() in startsWith().40do_test fts3al-1.3 {41  execsql "CREATE VIRTUAL TABLE t3 USING fts3(content, tokenize\x80)"42} {}43 44# The snippet-generation code has calls to isspace() which are sort of45# hard to get to.  It finds convenient breakpoints by starting ~4046# chars before and after the matched term, and scanning ~10 chars47# around that position for isspace() characters.  The long word with48# embedded hi-bit chars causes one of these isspace() calls to be49# exercised.  The version with a couple extra spaces should cause the50# other isspace() call to be exercised.  [Both cases have been tested51# in the debugger, but I'm hoping to continue to catch it if simple52# constant changes change things slightly.53#54# The trailing and leading hi-bit chars help with code which tests for55# isspace() to coalesce multiple spaces.56#57# UPDATE: The above is no longer true; there is no such code in fts3.58# But leave the test in just the same.59# 60 61set word "\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80"62set phrase1 "$word $word $word target $word $word $word"63set phrase2 "$word $word $word    target    $word $word $word"64 65db eval {CREATE VIRTUAL TABLE t4 USING fts3(content)}66db eval "INSERT INTO t4 (content) VALUES ('$phrase1')"67db eval "INSERT INTO t4 (content) VALUES ('$phrase2')"68 69do_test fts3al-1.4 {70  execsql {SELECT rowid, length(snippet(t4)) FROM t4 WHERE t4 MATCH 'target'}71} {1 241 2 247}72 73finish_test74