3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Tests focusing on the built-in fts5 tokenizers.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5tokenizer2
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
24 sqlite3_fts5_create_tokenizer db tst get_tst_tokenizer
25 proc get_tst_tokenizer {args} {
26 return "tst_tokenizer"
28 proc tst_tokenizer {flags txt} {
32 foreach c [split $txt {}] {
36 set t1 [string is upper $token]
37 set t2 [string is upper $c]
46 if {$token!=""} { lappend lTok $token }
50 set n [string length $t]
51 sqlite3_fts5_token $t $iOff [expr $iOff+$n]
57 CREATE VIRTUAL TABLE t1 USING fts5(t, tokenize=tst);
61 INSERT INTO t1 VALUES('AAdontBBmess');
65 SELECT snippet(t1, 0, '>', '<', '...', 4) FROM t1('BB');
69 SELECT highlight(t1, 0, '>', '<') FROM t1('BB');
73 SELECT highlight(t1, 0, '>', '<') FROM t1('AA');
77 SELECT highlight(t1, 0, '>', '<') FROM t1('dont');
81 SELECT highlight(t1, 0, '>', '<') FROM t1('mess');
85 SELECT highlight(t1, 0, '>', '<') FROM t1('BB mess');
88 # 2024-08-06 https://sqlite.org/forum/forumpost/171bcc2bcd
89 # Error handling of tokenize= arguments.
101 db eval {DROP TABLE IF EXISTS t2;}
102 do_catchsql_test 2.$n "
103 DROP TABLE IF EXISTS t2;
104 CREATE VIRTUAL TABLE t2 USING fts5(a,b,c,tokenize='$tkz');
105 " {1 {error in tokenizer constructor}}