dan | 3174598 | 2010-01-07 10:54:28 +0000 | [diff] [blame^] | 1 | # 2010 January 07 |
| 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 | # |
dan | b023b04 | 2010-01-06 17:19:21 +0000 | [diff] [blame] | 12 | |
| 13 | set testdir [file dirname $argv0] |
| 14 | source $testdir/tester.tcl |
| 15 | |
dan | 3174598 | 2010-01-07 10:54:28 +0000 | [diff] [blame^] | 16 | # If SQLITE_ENABLE_FTS3 is not defined, omit this file. |
dan | b023b04 | 2010-01-06 17:19:21 +0000 | [diff] [blame] | 17 | ifcapable !fts3 { finish_test ; return } |
| 18 | |
dan | 3174598 | 2010-01-07 10:54:28 +0000 | [diff] [blame^] | 19 | # Transform the list $L to its "normal" form. So that it can be compared to |
| 20 | # another list with the same set of elements using [string compare]. |
| 21 | # |
| 22 | proc normalize {L} { |
| 23 | set ret [list] |
| 24 | foreach l $L {lappend ret $l} |
| 25 | return $ret |
| 26 | } |
| 27 | |
dan | b023b04 | 2010-01-06 17:19:21 +0000 | [diff] [blame] | 28 | do_test fts3snippet-1.1 { |
| 29 | execsql { |
| 30 | CREATE VIRTUAL TABLE ft USING fts3; |
| 31 | INSERT INTO ft VALUES('xxx xxx xxx xxx'); |
| 32 | } |
| 33 | } {} |
| 34 | |
dan | b023b04 | 2010-01-06 17:19:21 +0000 | [diff] [blame] | 35 | do_test fts3snippet-1.2 { |
| 36 | execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH 'xxx' } |
| 37 | } {{0 0 0 3 0 0 4 3 0 0 8 3 0 0 12 3}} |
| 38 | |
| 39 | do_test fts3snippet-1.3 { |
| 40 | execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH '"xxx xxx"' } |
| 41 | } [list [normalize { |
| 42 | 0 0 0 3 |
| 43 | 0 0 4 3 |
| 44 | 0 1 4 3 |
| 45 | 0 0 8 3 |
| 46 | 0 1 8 3 |
| 47 | 0 1 12 3 |
| 48 | }]] |
| 49 | |
| 50 | |
| 51 | do_test fts3snippet-1.4 { |
| 52 | execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH '"xxx xxx" xxx' } |
| 53 | } [list [normalize { |
| 54 | 0 0 0 3 |
| 55 | 0 2 0 3 |
| 56 | 0 0 4 3 |
| 57 | 0 1 4 3 |
| 58 | 0 2 4 3 |
| 59 | 0 0 8 3 |
| 60 | 0 1 8 3 |
| 61 | 0 2 8 3 |
| 62 | 0 1 12 3 |
| 63 | 0 2 12 3 |
| 64 | }]] |
| 65 | |
| 66 | do_test fts3snippet-1.5 { |
| 67 | execsql { SELECT offsets(ft) FROM ft WHERE ft MATCH 'xxx "xxx xxx"' } |
| 68 | } [list [normalize { |
| 69 | 0 0 0 3 |
| 70 | 0 1 0 3 |
| 71 | 0 0 4 3 |
| 72 | 0 1 4 3 |
| 73 | 0 2 4 3 |
| 74 | 0 0 8 3 |
| 75 | 0 1 8 3 |
| 76 | 0 2 8 3 |
| 77 | 0 0 12 3 |
| 78 | 0 2 12 3 |
| 79 | }]] |
| 80 | |
dan | 3174598 | 2010-01-07 10:54:28 +0000 | [diff] [blame^] | 81 | do_test fts3snippet-2.1 { |
| 82 | execsql { |
| 83 | DROP TABLE IF EXISTS ft; |
| 84 | CREATE VIRTUAL TABLE ft USING fts3; |
| 85 | INSERT INTO ft VALUES('one two three four five six seven eight nine ten'); |
| 86 | } |
| 87 | } {} |
| 88 | foreach {tn expr res} { |
| 89 | 1 one "[one] two three four five..." |
| 90 | 2 two "one [two] three four five..." |
| 91 | 3 three "one two [three] four five..." |
| 92 | 4 four "...two three [four] five six..." |
| 93 | 5 five "...three four [five] six seven..." |
| 94 | 6 six "...four five [six] seven eight..." |
| 95 | 7 seven "...five six [seven] eight nine..." |
| 96 | 8 eight "...six seven [eight] nine ten" |
| 97 | 9 nine "...six seven eight [nine] ten" |
| 98 | 10 ten "...six seven eight nine [ten]" |
| 99 | } { |
| 100 | do_test fts3snippet-2.2.$tn { |
| 101 | execsql { |
| 102 | SELECT snippet(ft, '[', ']', '...', 0, 5) FROM ft WHERE ft MATCH $expr |
| 103 | } |
| 104 | } [list $res] |
| 105 | } |
| 106 | |
dan | b023b04 | 2010-01-06 17:19:21 +0000 | [diff] [blame] | 107 | finish_test |
| 108 | |