fts2l.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # 2007 March 28
  2. #
  3. # The author disclaims copyright to this source code.
  4. #
  5. #*************************************************************************
  6. # This file implements regression tests for SQLite library. The focus
  7. # of this script is testing isspace/isalnum/tolower problems with the
  8. # FTS2 module. Unfortunately, this code isn't a really principled set
  9. # of tests, because it is impossible to know where new uses of these
  10. # functions might appear.
  11. #
  12. # $Id: fts2l.test,v 1.2 2007/12/13 21:54:11 drh Exp $
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. # If SQLITE_ENABLE_FTS2 is defined, omit this file.
  17. ifcapable !fts2 {
  18. finish_test
  19. return
  20. }
  21. # Tests that startsWith() (calls isspace, tolower, isalnum) can handle
  22. # hi-bit chars. parseSpec() also calls isalnum here.
  23. do_test fts2l-1.1 {
  24. execsql "CREATE VIRTUAL TABLE t1 USING fts2(content, \x80)"
  25. } {}
  26. # Additionally tests isspace() call in getToken(), and isalnum() call
  27. # in tokenListToIdList().
  28. do_test fts2l-1.2 {
  29. catch {
  30. execsql "CREATE VIRTUAL TABLE t2 USING fts2(content, tokenize \x80)"
  31. }
  32. sqlite3_errmsg $DB
  33. } "unknown tokenizer: \x80"
  34. # Additionally test final isalnum() in startsWith().
  35. do_test fts2l-1.3 {
  36. execsql "CREATE VIRTUAL TABLE t3 USING fts2(content, tokenize\x80)"
  37. } {}
  38. # The snippet-generation code has calls to isspace() which are sort of
  39. # hard to get to. It finds convenient breakpoints by starting ~40
  40. # chars before and after the matched term, and scanning ~10 chars
  41. # around that position for isspace() characters. The long word with
  42. # embedded hi-bit chars causes one of these isspace() calls to be
  43. # exercised. The version with a couple extra spaces should cause the
  44. # other isspace() call to be exercised. [Both cases have been tested
  45. # in the debugger, but I'm hoping to continue to catch it if simple
  46. # constant changes change things slightly.
  47. #
  48. # The trailing and leading hi-bit chars help with code which tests for
  49. # isspace() to coalesce multiple spaces.
  50. set word "\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80"
  51. set phrase1 "$word $word $word target $word $word $word"
  52. set phrase2 "$word $word $word target $word $word $word"
  53. db eval {CREATE VIRTUAL TABLE t4 USING fts2(content)}
  54. db eval "INSERT INTO t4 (content) VALUES ('$phrase1')"
  55. db eval "INSERT INTO t4 (content) VALUES ('$phrase2')"
  56. do_test fts2l-1.4 {
  57. execsql {SELECT rowid, length(snippet(t4)) FROM t4 WHERE t4 MATCH 'target'}
  58. } {1 111 2 117}
  59. finish_test