# 2007 June 21 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #************************************************************************* # This file implements regression tests for SQLite library. The focus # of this script is testing the pluggable tokeniser feature of the # FTS2 module. # # $Id: fts2token.test,v 1.1 2007/06/22 15:21:16 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl # If SQLITE_ENABLE_FTS2 is defined, omit this file. ifcapable !fts2 { finish_test return } #-------------------------------------------------------------------------- # Test cases fts2token-1.* are the warm-body test for the SQL scalar # function fts2_tokenizer(). The procedure is as follows: # # 1: Verify that there is no such fts2 tokenizer as 'blah'. # # 2: Query for the built-in tokenizer 'simple'. Insert a copy of the # retrieved value as tokenizer 'blah'. # # 3: Test that the value returned for tokenizer 'blah' is now the # same as that retrieved for 'simple'. # # 4: Test that it is now possible to create an fts2 table using # tokenizer 'blah' (it was not possible in step 1). # # 5: Test that the table created to use tokenizer 'blah' is usable. # do_test fts2token-1.1 { catchsql { CREATE VIRTUAL TABLE t1 USING fts2(content, tokenize blah); } } {1 {unknown tokenizer: blah}} do_test fts2token-1.2 { execsql { SELECT fts2_tokenizer('blah', fts2_tokenizer('simple')) IS NULL; } } {0} do_test fts2token-1.3 { execsql { SELECT fts2_tokenizer('blah') == fts2_tokenizer('simple'); } } {1} do_test fts2token-1.4 { catchsql { CREATE VIRTUAL TABLE t1 USING fts2(content, tokenize blah); } } {0 {}} do_test fts2token-1.5 { execsql { INSERT INTO t1(content) VALUES('There was movement at the station'); INSERT INTO t1(content) VALUES('For the word has passed around'); INSERT INTO t1(content) VALUES('That the colt from ol regret had got away'); SELECT content FROM t1 WHERE content MATCH 'movement' } } {{There was movement at the station}} #-------------------------------------------------------------------------- # Test cases fts2token-2.* test error cases in the scalar function based # API for getting and setting tokenizers. # do_test fts2token-2.1 { catchsql { SELECT fts2_tokenizer('nosuchtokenizer'); } } {1 {unknown tokenizer: nosuchtokenizer}} #-------------------------------------------------------------------------- # Test cases fts2token-3.* test the three built-in tokenizers with a # simple input string via the built-in test function. This is as much # to test the test function as the tokenizer implementations. # do_test fts2token-3.1 { execsql { SELECT fts2_tokenizer_test('simple', 'I don''t see how'); } } {{0 i I 1 don don 2 t t 3 see see 4 how how}} do_test fts2token-3.2 { execsql { SELECT fts2_tokenizer_test('porter', 'I don''t see how'); } } {{0 i I 1 don don 2 t t 3 see see 4 how how}} ifcapable icu { do_test fts2token-3.3 { execsql { SELECT fts2_tokenizer_test('icu', 'I don''t see how'); } } {{0 i I 1 don't don't 2 see see 3 how how}} } finish_test