interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / fts3atoken2.test

110 lines · 3115 bytes Raw Blame History
1# 2025 September 5
2#
3# The author disclaims copyright to this source code. In place of
4# 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.tcl
18
19# If SQLITE_ENABLE_FTS3 is defined, omit this file.
20ifcapable !fts3 {
21 finish_test
22 return
23}
24
25set ::testprefix fts3atoken2
26
27
28reset_db
29sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 0
30
31# With ENABLE_FTS3_TOKENIZER set to 0:
32#
33# * It is not possible to get a pointer to a token implementation
34# using single arg fts3_tokenize() unless the name of the tokenizer
35# 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 anything
50# 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 either
73# a bound parameter or a literal.
74#
75sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1
76set 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 either
87# 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
92if {[filc_build]==0} {
93 # Omit these two tests with Fil-C, as it will abort() if a pointer
94 # decoded from an SQL literal is dereferenced.
95 do_execsql_test 1.4.1 "
96 SELECT typeof( fts3_tokenizer('mytok2', $literal) );
97 " {blob}
98 do_execsql_test 1.4.2 {
99 CREATE VIRTUAL TABLE x2 USING fts3(col, tokenize=mytok2);
100 }
101}
102do_execsql_test 1.4.3 {
103 SELECT typeof( fts3_tokenizer('mytok3', $blob) );
104} {blob}
105do_execsql_test 1.4.4 {
106 CREATE VIRTUAL TABLE x3 USING fts3(col, tokenize=mytok3);
107}
108
109finish_test
110