/ Check-in [34f68546]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix test numbering in fts3snippet.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:34f6854685f00158bc536dd53ac5bc20e19fe071
User & Date: dan 2010-01-15 17:33:50
Context
2010-01-18
18:17
Fix a problem with the CLI where not all SQL commands were being echoed. Added tests of same to tools/shell2.test. Ticket [eb620916be]. check-in: 7080ae3b user: shaneh tags: trunk
2010-01-15
17:33
Fix test numbering in fts3snippet.test. check-in: 34f68546 user: dan tags: trunk
17:25
Add coverage tests for fts3_snippet.c. Also fixes related to the same. check-in: 5e9d8cca user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/fts3snippet.test.

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
  }
  do_offsets_test $T.1.5 {xxx "xxx xxx"} {
      0 0  0 3     0 1  0 3     0 0  4 3     0 1  4 3 
      0 2  4 3     0 0  8 3     0 1  8 3     0 2  8 3 
      0 0 12 3     0 2 12 3
  }

  do_test $T.9.1 {
    set v1 [lrange $numbers 0 99]
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3(a, b);
      INSERT INTO ft VALUES($v1, $numbers);
      INSERT INTO ft VALUES($v1, NULL);
    }
  } {}

  set off [string first "twohundred " $numbers]
  do_offsets_test $T.9.1 {twohundred} [list 1 0 $off 10]

  set off [string first "onehundred " $numbers]
  do_offsets_test $T.9.2 {onehundred} \
    [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]

  # Test a corruption case:
  execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }
  do_error_test $T.9.3 {
    SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
  } {database disk image is malformed}
  
  ##########################################################################
  # Test the snippet function.
  #
  proc do_snippet_test {name expr iCol nTok args} {
    set res [list]
    foreach a $args { lappend res [string trim $a] }
    do_select_test $name {
      SELECT snippet(ft,'{','}','...',$iCol,$nTok) FROM ft WHERE ft MATCH $expr
    } $res
  }
  do_test $T.2.1 {
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3;
      INSERT INTO ft VALUES('one two three four five six seven eight nine ten');
    }
  } {}
  do_snippet_test $T.2.2  one    0 5 "{one} two three four five..."
  do_snippet_test $T.2.3  two    0 5 "one {two} three four five..."
  do_snippet_test $T.2.4  three  0 5 "one two {three} four five..."
  do_snippet_test $T.2.5  four   0 5 "...two three {four} five six..."
  do_snippet_test $T.2.6  five   0 5 "...three four {five} six seven..."
  do_snippet_test $T.2.7  six    0 5 "...four five {six} seven eight..."
  do_snippet_test $T.2.8  seven  0 5 "...five six {seven} eight nine..."
  do_snippet_test $T.2.9  eight  0 5 "...six seven {eight} nine ten"
  do_snippet_test $T.2.10 nine   0 5 "...six seven eight {nine} ten"
  do_snippet_test $T.2.11 ten    0 5 "...six seven eight nine {ten}"
  
  do_test $T.3.1 {
    execsql {
      INSERT INTO ft VALUES(
           'one two three four five '
        || 'six seven eight nine ten '
        || 'eleven twelve thirteen fourteen fifteen '
        || 'sixteen seventeen eighteen nineteen twenty '
        || 'one two three four five '
................................................................................
        || 'six seven eight nine ten '
        || 'eleven twelve thirteen fourteen fifteen '
        || 'sixteen seventeen eighteen nineteen twenty'
      );
    }
  } {}
  
  do_snippet_test $T.3.2 {one nine} 0 5 {
     {one} two three...eight {nine} ten
  } {
     {one} two three...eight {nine} ten...
  }
  
  do_snippet_test $T.3.3 {one nine} 0 -5 {
     {one} two three four five...six seven eight {nine} ten
  } {
     {one} two three four five...seven eight {nine} ten eleven...
  }
  do_snippet_test $T.3.3 {one nineteen} 0 -5 {
     ...eighteen {nineteen} twenty {one} two...
  }
  do_snippet_test $T.3.4 {two nineteen} 0 -5 {
     ...eighteen {nineteen} twenty one {two}...
  }
  do_snippet_test $T.3.5 {three nineteen} 0 -5 {
     ...{nineteen} twenty one two {three}...
  }
  
  do_snippet_test $T.3.6 {four nineteen} 0 -5 {
     ...two three {four} five six...seventeen eighteen {nineteen} twenty one...
  }
  do_snippet_test $T.3.7 {four NEAR nineteen} 0 -5 {
     ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  }
  
  do_snippet_test $T.3.8 {four nineteen} 0 5 {
     ...three {four} five...eighteen {nineteen} twenty...
  }
  do_snippet_test $T.3.9 {four NEAR nineteen} 0 5 {
     ...eighteen {nineteen} twenty...three {four} five...
  }
  do_snippet_test $T.3.10 {four NEAR nineteen} 0 -5 {
     ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  }
  do_snippet_test $T.3.11 {four NOT (nineteen twentyone)} 0 5 {
     ...two three {four} five six...
  } {
     ...two three {four} five six...
  }
  do_snippet_test $T.3.12 {four OR nineteen NEAR twentyone} 0 5 {
     ...two three {four} five six...
  } {
     ...two three {four} five six...
  }
  
  do_test $T.5.1 {
    execsql {
................................................................................
  proc do_matchinfo_test {name expr args} {
    set res [list]
    foreach a $args { lappend res [normalize $a] }
    do_select_test $name {
      SELECT mit(matchinfo(ft)) FROM ft WHERE ft MATCH $expr
    } $res
  }
  do_test $T.4.1 {
    set ten {one two three four five six seven eight nine ten}
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3;
      INSERT INTO ft VALUES($ten);
      INSERT INTO ft VALUES($ten || ' ' || $ten);
    }
  } {}
  
  do_matchinfo_test $T.4.2 "one" {1 1  1 3 2} {1 1  2 3 2}
  do_matchinfo_test $T.4.3 "one NEAR/3 ten" {2 1  1 1 1 1 1 1}
  do_matchinfo_test $T.4.4 "five NEAR/4 ten" \
    {2 1  1 3 2  1 3 2} {2 1  2 3 2  2 3 2}
  do_matchinfo_test $T.4.5 "six NEAR/3 ten NEAR/3 two" \
    {3 1  1 1 1  1 1 1  1 1 1}
  do_matchinfo_test $T.4.6 "five NEAR/4 ten NEAR/3 two" \
    {3 1  2 2 1  1 1 1  1 1 1}

  do_test $T.8.1 {
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3(x, y);
    }
    foreach n {1 2 3} {
      set v1 [lrange $numbers 0 [expr $n*100]]
      set v2 [string trim [string repeat "$numbers " $n]]
      set docid [expr $n * 1000000]
      execsql { INSERT INTO ft(docid, x, y) VALUES($docid, $v1, $v2) }
    }
  } {}
  do_matchinfo_test $T.8.2 {two*}     \
    { 1 2    1   105 3   101 606 3}   \
    { 1 2    3   105 3   202 606 3}   \
    { 1 2    101 105 3   303 606 3}

  do_matchinfo_test $T.8.4 {"one* two*"}  \
    { 1 2    1 5 3   2 12 3}              \
    { 1 2    2 5 3   4 12 3}              \
    { 1 2    2 5 3   6 12 3}

  do_matchinfo_test $T.8.5 {twohundredfifty}  \
    { 1 2    0 1 1   1 6 3}                   \
    { 1 2    0 1 1   2 6 3}                   \
    { 1 2    1 1 1   3 6 3}

  do_matchinfo_test $T.8.6 {"threehundred one"} \
    { 1 2    0 0 0   1 3 2}                     \
    { 1 2    0 0 0   2 3 2}

  do_matchinfo_test $T.8.7 {one OR fivehundred} \
    { 2 2    1 3 3   1 6 3   0 0 0   0 0 0 }    \
    { 2 2    1 3 3   2 6 3   0 0 0   0 0 0 }    \
    { 2 2    1 3 3   3 6 3   0 0 0   0 0 0 }

  do_matchinfo_test $T.8.8 {two OR "threehundred one"} \
    { 2 2    1 3 3   1 6 3   0 0 0   0 3 2 }           \
    { 2 2    1 3 3   2 6 3   0 0 0   1 3 2 }           \
    { 2 2    1 3 3   3 6 3   0 0 0   2 3 2 }

  do_select_test $T.8.9 {
    SELECT mit(matchinfo(ft)), mit(matchinfo(ft))
    FROM ft WHERE ft MATCH 'two OR "threehundred one"' 
  } [normalize {
    {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
    {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
    {2 2 1 3 3 2 6 3 0 0 0 1 3 2}
    {2 2 1 3 3 2 6 3 0 0 0 1 3 2}







|










|


|




|













|






|
|
|
|
|
|
|
|
|
|

|







 







|





|




|


|


|



|


|



|


|


|


|




|







 







|









|
|
|

|

|


|











|




|




|




|



|




|




|







161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
  }
  do_offsets_test $T.1.5 {xxx "xxx xxx"} {
      0 0  0 3     0 1  0 3     0 0  4 3     0 1  4 3 
      0 2  4 3     0 0  8 3     0 1  8 3     0 2  8 3 
      0 0 12 3     0 2 12 3
  }

  do_test $T.2.1 {
    set v1 [lrange $numbers 0 99]
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3(a, b);
      INSERT INTO ft VALUES($v1, $numbers);
      INSERT INTO ft VALUES($v1, NULL);
    }
  } {}

  set off [string first "twohundred " $numbers]
  do_offsets_test $T.2.1 {twohundred} [list 1 0 $off 10]

  set off [string first "onehundred " $numbers]
  do_offsets_test $T.2.2 {onehundred} \
    [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]

  # Test a corruption case:
  execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }
  do_error_test $T.2.3 {
    SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
  } {database disk image is malformed}
  
  ##########################################################################
  # Test the snippet function.
  #
  proc do_snippet_test {name expr iCol nTok args} {
    set res [list]
    foreach a $args { lappend res [string trim $a] }
    do_select_test $name {
      SELECT snippet(ft,'{','}','...',$iCol,$nTok) FROM ft WHERE ft MATCH $expr
    } $res
  }
  do_test $T.3.1 {
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3;
      INSERT INTO ft VALUES('one two three four five six seven eight nine ten');
    }
  } {}
  do_snippet_test $T.3.2  one    0 5 "{one} two three four five..."
  do_snippet_test $T.3.3  two    0 5 "one {two} three four five..."
  do_snippet_test $T.3.4  three  0 5 "one two {three} four five..."
  do_snippet_test $T.3.5  four   0 5 "...two three {four} five six..."
  do_snippet_test $T.3.6  five   0 5 "...three four {five} six seven..."
  do_snippet_test $T.3.7  six    0 5 "...four five {six} seven eight..."
  do_snippet_test $T.3.8  seven  0 5 "...five six {seven} eight nine..."
  do_snippet_test $T.3.9  eight  0 5 "...six seven {eight} nine ten"
  do_snippet_test $T.3.10 nine   0 5 "...six seven eight {nine} ten"
  do_snippet_test $T.3.11 ten    0 5 "...six seven eight nine {ten}"
  
  do_test $T.4.1 {
    execsql {
      INSERT INTO ft VALUES(
           'one two three four five '
        || 'six seven eight nine ten '
        || 'eleven twelve thirteen fourteen fifteen '
        || 'sixteen seventeen eighteen nineteen twenty '
        || 'one two three four five '
................................................................................
        || 'six seven eight nine ten '
        || 'eleven twelve thirteen fourteen fifteen '
        || 'sixteen seventeen eighteen nineteen twenty'
      );
    }
  } {}
  
  do_snippet_test $T.4.2 {one nine} 0 5 {
     {one} two three...eight {nine} ten
  } {
     {one} two three...eight {nine} ten...
  }
  
  do_snippet_test $T.4.3 {one nine} 0 -5 {
     {one} two three four five...six seven eight {nine} ten
  } {
     {one} two three four five...seven eight {nine} ten eleven...
  }
  do_snippet_test $T.4.3 {one nineteen} 0 -5 {
     ...eighteen {nineteen} twenty {one} two...
  }
  do_snippet_test $T.4.4 {two nineteen} 0 -5 {
     ...eighteen {nineteen} twenty one {two}...
  }
  do_snippet_test $T.4.5 {three nineteen} 0 -5 {
     ...{nineteen} twenty one two {three}...
  }
  
  do_snippet_test $T.4.6 {four nineteen} 0 -5 {
     ...two three {four} five six...seventeen eighteen {nineteen} twenty one...
  }
  do_snippet_test $T.4.7 {four NEAR nineteen} 0 -5 {
     ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  }
  
  do_snippet_test $T.4.8 {four nineteen} 0 5 {
     ...three {four} five...eighteen {nineteen} twenty...
  }
  do_snippet_test $T.4.9 {four NEAR nineteen} 0 5 {
     ...eighteen {nineteen} twenty...three {four} five...
  }
  do_snippet_test $T.4.10 {four NEAR nineteen} 0 -5 {
     ...seventeen eighteen {nineteen} twenty one...two three {four} five six...
  }
  do_snippet_test $T.4.11 {four NOT (nineteen twentyone)} 0 5 {
     ...two three {four} five six...
  } {
     ...two three {four} five six...
  }
  do_snippet_test $T.4.12 {four OR nineteen NEAR twentyone} 0 5 {
     ...two three {four} five six...
  } {
     ...two three {four} five six...
  }
  
  do_test $T.5.1 {
    execsql {
................................................................................
  proc do_matchinfo_test {name expr args} {
    set res [list]
    foreach a $args { lappend res [normalize $a] }
    do_select_test $name {
      SELECT mit(matchinfo(ft)) FROM ft WHERE ft MATCH $expr
    } $res
  }
  do_test $T.8.1 {
    set ten {one two three four five six seven eight nine ten}
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3;
      INSERT INTO ft VALUES($ten);
      INSERT INTO ft VALUES($ten || ' ' || $ten);
    }
  } {}
  
  do_matchinfo_test $T.8.2 "one" {1 1  1 3 2} {1 1  2 3 2}
  do_matchinfo_test $T.8.3 "one NEAR/3 ten" {2 1  1 1 1 1 1 1}
  do_matchinfo_test $T.8.4 "five NEAR/4 ten" \
    {2 1  1 3 2  1 3 2} {2 1  2 3 2  2 3 2}
  do_matchinfo_test $T.8.5 "six NEAR/3 ten NEAR/3 two" \
    {3 1  1 1 1  1 1 1  1 1 1}
  do_matchinfo_test $T.8.6 "five NEAR/4 ten NEAR/3 two" \
    {3 1  2 2 1  1 1 1  1 1 1}

  do_test $T.9.1 {
    execsql {
      DROP TABLE IF EXISTS ft;
      CREATE VIRTUAL TABLE ft USING fts3(x, y);
    }
    foreach n {1 2 3} {
      set v1 [lrange $numbers 0 [expr $n*100]]
      set v2 [string trim [string repeat "$numbers " $n]]
      set docid [expr $n * 1000000]
      execsql { INSERT INTO ft(docid, x, y) VALUES($docid, $v1, $v2) }
    }
  } {}
  do_matchinfo_test $T.9.2 {two*}     \
    { 1 2    1   105 3   101 606 3}   \
    { 1 2    3   105 3   202 606 3}   \
    { 1 2    101 105 3   303 606 3}

  do_matchinfo_test $T.9.4 {"one* two*"}  \
    { 1 2    1 5 3   2 12 3}              \
    { 1 2    2 5 3   4 12 3}              \
    { 1 2    2 5 3   6 12 3}

  do_matchinfo_test $T.9.5 {twohundredfifty}  \
    { 1 2    0 1 1   1 6 3}                   \
    { 1 2    0 1 1   2 6 3}                   \
    { 1 2    1 1 1   3 6 3}

  do_matchinfo_test $T.9.6 {"threehundred one"} \
    { 1 2    0 0 0   1 3 2}                     \
    { 1 2    0 0 0   2 3 2}

  do_matchinfo_test $T.9.7 {one OR fivehundred} \
    { 2 2    1 3 3   1 6 3   0 0 0   0 0 0 }    \
    { 2 2    1 3 3   2 6 3   0 0 0   0 0 0 }    \
    { 2 2    1 3 3   3 6 3   0 0 0   0 0 0 }

  do_matchinfo_test $T.9.8 {two OR "threehundred one"} \
    { 2 2    1 3 3   1 6 3   0 0 0   0 3 2 }           \
    { 2 2    1 3 3   2 6 3   0 0 0   1 3 2 }           \
    { 2 2    1 3 3   3 6 3   0 0 0   2 3 2 }

  do_select_test $T.9.9 {
    SELECT mit(matchinfo(ft)), mit(matchinfo(ft))
    FROM ft WHERE ft MATCH 'two OR "threehundred one"' 
  } [normalize {
    {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
    {2 2 1 3 3 1 6 3 0 0 0 0 3 2}
    {2 2 1 3 3 2 6 3 0 0 0 1 3 2}
    {2 2 1 3 3 2 6 3 0 0 0 1 3 2}