AryaWu/sqlite
0
1# 2025 September 52#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#*************************************************************************11# This file implements regression tests for SQLite library. The focus 12# of this script is testing the pluggable tokeniser feature of the 13# FTS3 module.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18 19# If SQLITE_ENABLE_FTS3 is defined, omit this file.20ifcapable !fts3 {21 finish_test22 return23}24 25set ::testprefix fts3atoken226 27 28reset_db29sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 030 31# With ENABLE_FTS3_TOKENIZER set to 0:32#33# * It is not possible to get a pointer to a token implementation34# using single arg fts3_tokenize() unless the name of the tokenizer35# is a bound paramter - function should return NULL.36#37# * But it is possible with a bound parameter.38#39do_execsql_test 1.1.1 {40 SELECT typeof( fts3_tokenizer('simple') );41} {null}42set bound "simple"43do_execsql_test 1.1.2 {44 SELECT typeof( fts3_tokenizer($bound) );45} {blob}46 47# With ENABLE_FTS3_TOKENIZER set to 0:48#49# * It is not possible to create a token implementation using anything50# other than a bound parameter.51#52# * But it is possible with a bound parameter.53#54set literal [db one {SELECT quote( fts3_tokenizer($bound) )}]55set blob [db one {SELECT fts3_tokenizer($bound) }]56 57do_catchsql_test 1.2.1 "58 SELECT fts3_tokenizer('mytok', $literal)59" {1 {fts3tokenize disabled}}60do_catchsql_test 1.2.2 {61 CREATE VIRTUAL TABLE x1 USING fts3(col, tokenize=mytok);62} {1 {unknown tokenizer: mytok}}63do_catchsql_test 1.2.3 {64 SELECT fts3_tokenizer('mytok', $blob)65} {0 {{}}}66do_execsql_test 1.2.4 {67 CREATE VIRTUAL TABLE x1 USING fts3(col, tokenize=mytok);68}69 70# With ENABLE_FTS3_TOKENIZER set to 1:71#72# * It is possible to get a pointer to a token implementation with either73# a bound parameter or a literal.74#75sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 176set bound "simple"77do_execsql_test 1.3.1 {78 SELECT typeof( fts3_tokenizer('simple') );79} {blob}80do_execsql_test 1.3.2 {81 SELECT typeof( fts3_tokenizer($bound) );82} {blob}83 84# With ENABLE_FTS3_TOKENIZER set to 1:85#86# * It is not possible to create a token implementation using either87# a bound parameter or a literal.88#89set literal [db one {SELECT quote( fts3_tokenizer($bound) )}]90set blob [db one {SELECT fts3_tokenizer($bound) }]91 92do_execsql_test 1.4.1 "93 SELECT typeof( fts3_tokenizer('mytok2', $literal) );94" {blob}95do_execsql_test 1.4.2 {96 CREATE VIRTUAL TABLE x2 USING fts3(col, tokenize=mytok2);97}98do_execsql_test 1.4.3 {99 SELECT typeof( fts3_tokenizer('mytok3', $blob) );100} {blob}101do_execsql_test 1.4.4 {102 CREATE VIRTUAL TABLE x3 USING fts3(col, tokenize=mytok3);103}104 105finish_test106 107 