sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | # 2013 April 22 |
| 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 |
| 12 | # focus of this script is testing the "fts3tokenize" virtual table |
| 13 | # that is part of the FTS3 module. |
| 14 | # |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | ifcapable !fts3 { finish_test ; return } |
| 19 | set ::testprefix fts3tok1 |
| 20 | |
| 21 | #------------------------------------------------------------------------- |
| 22 | # Simple test cases. Using the default (simple) tokenizer. |
| 23 | # |
| 24 | do_execsql_test 1.0 { |
| 25 | CREATE VIRTUAL TABLE t1 USING fts3tokenize(simple); |
| 26 | CREATE VIRTUAL TABLE t2 USING fts3tokenize(); |
| 27 | CREATE VIRTUAL TABLE t3 USING fts3tokenize(simple, '', 'xyz '); |
| 28 | } |
| 29 | |
| 30 | foreach {tn tbl} {1 t1 2 t2 3 t3} { |
| 31 | do_execsql_test 1.$tn.1 "SELECT * FROM $tbl WHERE input = 'one two three'" { |
| 32 | {one two three} one 0 3 0 |
| 33 | {one two three} two 4 7 1 |
| 34 | {one two three} three 8 13 2 |
| 35 | } |
| 36 | |
| 37 | do_execsql_test 1.$tn.2 " |
| 38 | SELECT token FROM $tbl WHERE input = 'OnE tWo tHrEe' |
| 39 | " { |
| 40 | one two three |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | do_execsql_test 1.4 { |
| 45 | SELECT token FROM t3 WHERE input = '1x2x3x' |
| 46 | } {1 2 3} |
| 47 | |
| 48 | do_execsql_test 1.5 { |
| 49 | SELECT token FROM t1 WHERE input = '1x2x3x' |
| 50 | } {1x2x3x} |
| 51 | |
| 52 | do_execsql_test 1.6 { |
| 53 | SELECT token FROM t3 WHERE input = '1''2x3x' |
| 54 | } {1'2 3} |
| 55 | |
| 56 | do_execsql_test 1.7 { |
| 57 | SELECT token FROM t3 WHERE input = '' |
| 58 | } {} |
| 59 | |
| 60 | do_execsql_test 1.8 { |
| 61 | SELECT token FROM t3 WHERE input = NULL |
| 62 | } {} |
| 63 | |
| 64 | do_execsql_test 1.9 { |
| 65 | SELECT * FROM t3 WHERE input = 123 |
| 66 | } {123 123 0 3 0} |
| 67 | |
| 68 | do_execsql_test 1.10 { |
| 69 | SELECT * FROM t1 WHERE input = 'a b c' AND token = 'b'; |
| 70 | } { |
| 71 | {a b c} b 2 3 1 |
| 72 | } |
| 73 | |
| 74 | do_execsql_test 1.11 { |
| 75 | SELECT * FROM t1 WHERE token = 'b' AND input = 'a b c'; |
| 76 | } { |
| 77 | {a b c} b 2 3 1 |
| 78 | } |
| 79 | |
| 80 | do_execsql_test 1.12 { |
| 81 | SELECT * FROM t1 WHERE input < 'b' AND input = 'a b c'; |
| 82 | } { |
| 83 | {a b c} a 0 1 0 |
| 84 | {a b c} b 2 3 1 |
| 85 | {a b c} c 4 5 2 |
| 86 | } |
| 87 | |
| 88 | do_execsql_test 1.13.1 { |
| 89 | CREATE TABLE c1(x); |
| 90 | INSERT INTO c1(x) VALUES('a b c'); |
| 91 | INSERT INTO c1(x) VALUES('d e f'); |
| 92 | } |
| 93 | do_execsql_test 1.13.2 { |
| 94 | SELECT * FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid; |
| 95 | } { |
| 96 | {a b c} {a b c} a 0 1 0 |
| 97 | {d e f} {d e f} e 2 3 1 |
| 98 | } |
| 99 | |
| 100 | |
| 101 | #------------------------------------------------------------------------- |
| 102 | # Error cases. |
| 103 | # |
| 104 | do_catchsql_test 2.0 { |
| 105 | CREATE VIRTUAL TABLE tX USING fts3tokenize(nosuchtokenizer); |
| 106 | } {1 {unknown tokenizer: nosuchtokenizer}} |
| 107 | |
| 108 | do_catchsql_test 2.1 { |
| 109 | CREATE VIRTUAL TABLE t4 USING fts3tokenize; |
| 110 | SELECT * FROM t4; |
| 111 | } {1 {SQL logic error}} |
| 112 | |
| 113 | do_catchsql_test 2.2 { |
| 114 | CREATE VIRTUAL TABLE t USING fts4(tokenize=simple""); |
| 115 | } {0 {}} |
| 116 | |
| 117 | ifcapable fts3_unicode { |
| 118 | do_catchsql_test 2.3 { |
| 119 | CREATE VIRTUAL TABLE u USING fts4(tokenize=unicode61""); |
| 120 | } {1 {unknown tokenizer}} |
| 121 | } |
| 122 | |
| 123 | |
| 124 | finish_test |