OLD | NEW |
1 # 2008 June 26 | 1 # 2008 June 26 |
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 # This file exercises some new testing functions in the FTS3 module, | 11 # This file exercises some new testing functions in the FTS3 module, |
12 # and then uses them to do some basic tests that FTS3 is internally | 12 # and then uses them to do some basic tests that FTS3 is internally |
13 # working as expected. | 13 # working as expected. |
14 # | 14 # |
15 # $Id: fts3c.test,v 1.1 2008/07/03 19:53:22 shess Exp $ | |
16 # | |
17 | 15 |
18 set testdir [file dirname $argv0] | 16 set testdir [file dirname $argv0] |
19 source $testdir/tester.tcl | 17 source $testdir/tester.tcl |
| 18 source $testdir/fts3_common.tcl |
20 | 19 |
21 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. | 20 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. |
22 ifcapable !fts3 { | 21 ifcapable !fts3 { |
23 finish_test | 22 finish_test |
24 return | 23 return |
25 } | 24 } |
26 | 25 |
27 #************************************************************************* | 26 #************************************************************************* |
28 # Probe to see if support for these functions is compiled in. | |
29 # TODO(shess): Change main.mk to do the right thing and remove this test. | |
30 db eval { | |
31 DROP TABLE IF EXISTS t1; | |
32 CREATE VIRTUAL TABLE t1 USING fts3(c); | |
33 INSERT INTO t1 (docid, c) VALUES (1, 'x'); | |
34 } | |
35 | |
36 set s {SELECT dump_terms(t1, 1) FROM t1 LIMIT 1} | |
37 set r {1 {unable to use function dump_terms in the requested context}} | |
38 if {[catchsql $s]==$r} { | |
39 finish_test | |
40 return | |
41 } | |
42 | |
43 #************************************************************************* | |
44 # Test that the new functions give appropriate errors. | |
45 do_test fts3c-0.0 { | |
46 catchsql { | |
47 SELECT dump_terms(t1, 1) FROM t1 LIMIT 1; | |
48 } | |
49 } {1 {dump_terms: incorrect arguments}} | |
50 | |
51 do_test fts3c-0.1 { | |
52 catchsql { | |
53 SELECT dump_terms(t1, 0, 0, 0) FROM t1 LIMIT 1; | |
54 } | |
55 } {1 {dump_terms: incorrect arguments}} | |
56 | |
57 do_test fts3c-0.2 { | |
58 catchsql { | |
59 SELECT dump_terms(1, t1) FROM t1 LIMIT 1; | |
60 } | |
61 } {1 {unable to use function dump_terms in the requested context}} | |
62 | |
63 do_test fts3c-0.3 { | |
64 catchsql { | |
65 SELECT dump_terms(t1, 16, 16) FROM t1 LIMIT 1; | |
66 } | |
67 } {1 {dump_terms: segment not found}} | |
68 | |
69 do_test fts3c-0.4 { | |
70 catchsql { | |
71 SELECT dump_doclist(t1) FROM t1 LIMIT 1; | |
72 } | |
73 } {1 {dump_doclist: incorrect arguments}} | |
74 | |
75 do_test fts3c-0.5 { | |
76 catchsql { | |
77 SELECT dump_doclist(t1, NULL) FROM t1 LIMIT 1; | |
78 } | |
79 } {1 {dump_doclist: empty second argument}} | |
80 | |
81 do_test fts3c-0.6 { | |
82 catchsql { | |
83 SELECT dump_doclist(t1, '') FROM t1 LIMIT 1; | |
84 } | |
85 } {1 {dump_doclist: empty second argument}} | |
86 | |
87 do_test fts3c-0.7 { | |
88 catchsql { | |
89 SELECT dump_doclist(t1, 'a', 0) FROM t1 LIMIT 1; | |
90 } | |
91 } {1 {dump_doclist: incorrect arguments}} | |
92 | |
93 do_test fts3c-0.8 { | |
94 catchsql { | |
95 SELECT dump_doclist(t1, 'a', 0, 0, 0) FROM t1 LIMIT 1; | |
96 } | |
97 } {1 {dump_doclist: incorrect arguments}} | |
98 | |
99 do_test fts3c-0.9 { | |
100 catchsql { | |
101 SELECT dump_doclist(t1, 'a', 16, 16) FROM t1 LIMIT 1; | |
102 } | |
103 } {1 {dump_doclist: segment not found}} | |
104 | |
105 #************************************************************************* | |
106 # Utility function to check for the expected terms in the segment | 27 # Utility function to check for the expected terms in the segment |
107 # level/index. _all version does same but for entire index. | 28 # level/index. _all version does same but for entire index. |
108 proc check_terms {test level index terms} { | 29 proc check_terms {test level index terms} { |
109 # TODO(shess): Figure out why uplevel in do_test can't catch | 30 set where "level = $level AND idx = $index" |
110 # $level and $index directly. | 31 do_test $test.terms [list fts3_terms t1 $where] $terms |
111 set ::level $level | |
112 set ::index $index | |
113 do_test $test.terms { | |
114 execsql { | |
115 SELECT dump_terms(t1, $::level, $::index) FROM t1 LIMIT 1; | |
116 } | |
117 } [list $terms] | |
118 } | 32 } |
119 proc check_terms_all {test terms} { | 33 proc check_terms_all {test terms} { |
120 do_test $test.terms { | 34 do_test $test.terms [list fts3_terms t1 1] $terms |
121 execsql { | |
122 SELECT dump_terms(t1) FROM t1 LIMIT 1; | |
123 } | |
124 } [list $terms] | |
125 } | 35 } |
126 | 36 |
127 # Utility function to check for the expected doclist for the term in | 37 # Utility function to check for the expected doclist for the term in |
128 # segment level/index. _all version does same for entire index. | 38 # segment level/index. _all version does same for entire index. |
129 proc check_doclist {test level index term doclist} { | 39 proc check_doclist {test level index term doclist} { |
130 # TODO(shess): Again, why can't the non-:: versions work? | 40 set where "level = $level AND idx = $index" |
131 set ::term $term | 41 do_test $test [list fts3_doclist t1 $term $where] $doclist |
132 set ::level $level | |
133 set ::index $index | |
134 do_test $test { | |
135 execsql { | |
136 SELECT dump_doclist(t1, $::term, $::level, $::index) FROM t1 LIMIT 1; | |
137 } | |
138 } [list $doclist] | |
139 } | 42 } |
140 proc check_doclist_all {test term doclist} { | 43 proc check_doclist_all {test term doclist} { |
141 set ::term $term | 44 do_test $test [list fts3_doclist t1 $term 1] $doclist |
142 do_test $test { | |
143 execsql { | |
144 SELECT dump_doclist(t1, $::term) FROM t1 LIMIT 1; | |
145 } | |
146 } [list $doclist] | |
147 } | 45 } |
148 | 46 |
149 #************************************************************************* | 47 #************************************************************************* |
150 # Test the segments resulting from straight-forward inserts. | 48 # Test the segments resulting from straight-forward inserts. |
151 db eval { | 49 db eval { |
152 DROP TABLE IF EXISTS t1; | 50 DROP TABLE IF EXISTS t1; |
153 CREATE VIRTUAL TABLE t1 USING fts3(c); | 51 CREATE VIRTUAL TABLE t1 USING fts3(c); |
154 INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); | 52 INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); |
155 INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); | 53 INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); |
156 INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); | 54 INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 check_doclist_all fts3c-1.3.1.3 that {[2 0[0]]} | 246 check_doclist_all fts3c-1.3.1.3 that {[2 0[0]]} |
349 check_doclist_all fts3c-1.3.1.4 was {[2 0[1]]} | 247 check_doclist_all fts3c-1.3.1.4 was {[2 0[1]]} |
350 | 248 |
351 check_terms fts3c-1.3.2 0 0 {a test that was} | 249 check_terms fts3c-1.3.2 0 0 {a test that was} |
352 check_doclist fts3c-1.3.2.1 0 0 a {[2 0[2]]} | 250 check_doclist fts3c-1.3.2.1 0 0 a {[2 0[2]]} |
353 check_doclist fts3c-1.3.2.2 0 0 test {[2 0[3]]} | 251 check_doclist fts3c-1.3.2.2 0 0 test {[2 0[3]]} |
354 check_doclist fts3c-1.3.2.3 0 0 that {[2 0[0]]} | 252 check_doclist fts3c-1.3.2.3 0 0 that {[2 0[0]]} |
355 check_doclist fts3c-1.3.2.4 0 0 was {[2 0[1]]} | 253 check_doclist fts3c-1.3.2.4 0 0 was {[2 0[1]]} |
356 | 254 |
357 finish_test | 255 finish_test |
OLD | NEW |