| OLD | NEW |
| 1 # 2010 January 07 | 1 # 2010 January 07 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #************************************************************************* | 10 #************************************************************************* |
| 11 # | 11 # |
| 12 # The tests in this file test the FTS3 auxillary functions offsets(), | 12 # The tests in this file test the FTS3 auxillary functions offsets(), |
| 13 # snippet() and matchinfo() work. At time of writing, running this file | 13 # snippet() and matchinfo() work. At time of writing, running this file |
| 14 # provides full coverage of fts3_snippet.c. | 14 # provides full coverage of fts3_snippet.c. |
| 15 # | 15 # |
| 16 | 16 |
| 17 set testdir [file dirname $argv0] | 17 set testdir [file dirname $argv0] |
| 18 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
| 19 set testprefix fts3snippet |
| 19 | 20 |
| 20 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. | 21 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. |
| 21 ifcapable !fts3 { finish_test ; return } | 22 ifcapable !fts3 { finish_test ; return } |
| 22 source $testdir/fts3_common.tcl | 23 source $testdir/fts3_common.tcl |
| 23 | 24 |
| 24 set sqlite_fts3_enable_parentheses 1 | 25 set sqlite_fts3_enable_parentheses 1 |
| 25 set DO_MALLOC_TEST 0 | 26 set DO_MALLOC_TEST 0 |
| 26 | 27 |
| 27 # Transform the list $L to its "normal" form. So that it can be compared to | 28 # Transform the list $L to its "normal" form. So that it can be compared to |
| 28 # another list with the same set of elements using [string compare]. | 29 # another list with the same set of elements using [string compare]. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 threehundred | 125 threehundred |
| 125 }] | 126 }] |
| 126 | 127 |
| 127 foreach {DO_MALLOC_TEST enc} { | 128 foreach {DO_MALLOC_TEST enc} { |
| 128 0 utf8 | 129 0 utf8 |
| 129 1 utf8 | 130 1 utf8 |
| 130 1 utf16 | 131 1 utf16 |
| 131 } { | 132 } { |
| 132 | 133 |
| 133 db close | 134 db close |
| 134 file delete -force test.db | 135 forcedelete test.db |
| 135 sqlite3 db test.db | 136 sqlite3 db test.db |
| 136 sqlite3_db_config_lookaside db 0 0 0 | 137 sqlite3_db_config_lookaside db 0 0 0 |
| 137 db eval "PRAGMA encoding = \"$enc\"" | 138 db eval "PRAGMA encoding = \"$enc\"" |
| 138 | 139 |
| 139 # Set variable $T to the test name prefix for this iteration of the loop. | 140 # Set variable $T to the test name prefix for this iteration of the loop. |
| 140 # | 141 # |
| 141 set T "fts3snippet-$enc" | 142 set T "fts3snippet-1.$enc" |
| 142 | 143 |
| 143 ########################################################################## | 144 ########################################################################## |
| 144 # Test the offset function. | 145 # Test the offset function. |
| 145 # | 146 # |
| 146 do_test $T.1.1 { | 147 do_test $T.1.1 { |
| 147 execsql { | 148 execsql { |
| 148 CREATE VIRTUAL TABLE ft USING fts3; | 149 CREATE VIRTUAL TABLE ft USING fts3; |
| 149 INSERT INTO ft VALUES('xxx xxx xxx xxx'); | 150 INSERT INTO ft VALUES('xxx xxx xxx xxx'); |
| 150 } | 151 } |
| 151 } {} | 152 } {} |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft WHERE rowid = $r; | 453 SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft WHERE rowid = $r; |
| 453 } {0 text} | 454 } {0 text} |
| 454 do_select_test $T.10.5 { | 455 do_select_test $T.10.5 { |
| 455 SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft; | 456 SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft; |
| 456 } {0 blob 0 blob 0 blob} | 457 } {0 blob 0 blob 0 blob} |
| 457 do_select_test $T.10.6 { | 458 do_select_test $T.10.6 { |
| 458 SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft WHERE rowid = $r | 459 SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft WHERE rowid = $r |
| 459 } {0 blob} | 460 } {0 blob} |
| 460 } | 461 } |
| 461 | 462 |
| 463 #------------------------------------------------------------------------- |
| 464 # Test an interaction between the snippet() function and OR clauses. |
| 465 # |
| 466 do_execsql_test 2.1 { |
| 467 CREATE VIRTUAL TABLE t2 USING fts4; |
| 468 INSERT INTO t2 VALUES('one two three four five'); |
| 469 INSERT INTO t2 VALUES('two three four five one'); |
| 470 INSERT INTO t2 VALUES('three four five one two'); |
| 471 INSERT INTO t2 VALUES('four five one two three'); |
| 472 INSERT INTO t2 VALUES('five one two three four'); |
| 473 } |
| 474 |
| 475 do_execsql_test 2.2 { |
| 476 SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' |
| 477 } { |
| 478 {[one] two three [four] five} |
| 479 {two three [four] five [one]} |
| 480 {three [four] five [one] two} |
| 481 {[four] five [one] two three} |
| 482 {five [one] two three [four]} |
| 483 } |
| 484 |
| 485 do_execsql_test 2.3 { |
| 486 SELECT snippet(t2, '[', ']') FROM t2 |
| 487 WHERE t2 MATCH 'one OR (four AND six)' |
| 488 ORDER BY docid DESC |
| 489 } { |
| 490 {five [one] two three [four]} |
| 491 {[four] five [one] two three} |
| 492 {three [four] five [one] two} |
| 493 {two three [four] five [one]} |
| 494 {[one] two three [four] five} |
| 495 } |
| 496 |
| 497 do_execsql_test 2.4 { |
| 498 INSERT INTO t2 VALUES('six'); |
| 499 } |
| 500 |
| 501 do_execsql_test 2.5 { |
| 502 SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' |
| 503 } { |
| 504 {[one] two three [four] five} |
| 505 {two three [four] five [one]} |
| 506 {three [four] five [one] two} |
| 507 {[four] five [one] two three} |
| 508 {five [one] two three [four]} |
| 509 } |
| 510 |
| 511 do_execsql_test 2.6 { |
| 512 SELECT snippet(t2, '[', ']') FROM t2 |
| 513 WHERE t2 MATCH 'one OR (four AND six)' |
| 514 ORDER BY docid DESC |
| 515 } { |
| 516 {five [one] two three [four]} |
| 517 {[four] five [one] two three} |
| 518 {three [four] five [one] two} |
| 519 {two three [four] five [one]} |
| 520 {[one] two three [four] five} |
| 521 } |
| 522 |
| 462 set sqlite_fts3_enable_parentheses 0 | 523 set sqlite_fts3_enable_parentheses 0 |
| 463 finish_test | 524 finish_test |
| OLD | NEW |