blob: 0f848981d2d86d87bfb4a488e6c25b9569dec308 [file] [log] [blame]
dan31745982010-01-07 10:54:28 +00001# 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#
danb023b042010-01-06 17:19:21 +000012
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
dan31745982010-01-07 10:54:28 +000016# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
danb023b042010-01-06 17:19:21 +000017ifcapable !fts3 { finish_test ; return }
18
dan31745982010-01-07 10:54:28 +000019# 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#
22proc normalize {L} {
23 set ret [list]
24 foreach l $L {lappend ret $l}
25 return $ret
26}
27
danb023b042010-01-06 17:19:21 +000028do_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
danb023b042010-01-06 17:19:21 +000035do_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
39do_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
51do_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
66do_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
dan31745982010-01-07 10:54:28 +000081do_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} {}
88foreach {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
danb023b042010-01-06 17:19:21 +0000107finish_test
108