sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / test / fts3atoken2.test
| 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 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | # If SQLITE_ENABLE_FTS3 is defined, omit this file. |
| 20 | ifcapable !fts3 { |
| 21 | finish_test |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | set ::testprefix fts3atoken2 |
| 26 | |
| 27 | |
| 28 | reset_db |
| 29 | sqlite3_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 | # |
| 39 | do_execsql_test 1.1.1 { |
| 40 | SELECT typeof( fts3_tokenizer('simple') ); |
| 41 | } {null} |
| 42 | set bound "simple" |
| 43 | do_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 | # |
| 54 | set literal [db one {SELECT quote( fts3_tokenizer($bound) )}] |
| 55 | set blob [db one {SELECT fts3_tokenizer($bound) }] |
| 56 | |
| 57 | do_catchsql_test 1.2.1 " |
| 58 | SELECT fts3_tokenizer('mytok', $literal) |
| 59 | " {1 {fts3tokenize disabled}} |
| 60 | do_catchsql_test 1.2.2 { |
| 61 | CREATE VIRTUAL TABLE x1 USING fts3(col, tokenize=mytok); |
| 62 | } {1 {unknown tokenizer: mytok}} |
| 63 | do_catchsql_test 1.2.3 { |
| 64 | SELECT fts3_tokenizer('mytok', $blob) |
| 65 | } {0 {{}}} |
| 66 | do_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 | # |
| 75 | sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 |
| 76 | set bound "simple" |
| 77 | do_execsql_test 1.3.1 { |
| 78 | SELECT typeof( fts3_tokenizer('simple') ); |
| 79 | } {blob} |
| 80 | do_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 | # |
| 89 | set literal [db one {SELECT quote( fts3_tokenizer($bound) )}] |
| 90 | set blob [db one {SELECT fts3_tokenizer($bound) }] |
| 91 | |
| 92 | if {[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 | } |
| 102 | do_execsql_test 1.4.3 { |
| 103 | SELECT typeof( fts3_tokenizer('mytok3', $blob) ); |
| 104 | } {blob} |
| 105 | do_execsql_test 1.4.4 { |
| 106 | CREATE VIRTUAL TABLE x3 USING fts3(col, tokenize=mytok3); |
| 107 | } |
| 108 | |
| 109 | finish_test |
| 110 |