fts3al.test 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # FTS3 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: fts3al.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_FTS3 is defined, omit this file.
  17. ifcapable !fts3 {
  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 fts3al-1.1 {
  24. execsql "CREATE VIRTUAL TABLE t1 USING fts3(content, \x80)"
  25. } {}
  26. # Additionally tests isspace() call in getToken(), and isalnum() call
  27. # in tokenListToIdList().
  28. do_test fts3al-1.2 {
  29. catch {
  30. execsql "CREATE VIRTUAL TABLE t2 USING fts3(content, tokenize \x80)"
  31. }
  32. sqlite3_errmsg $DB
  33. } "unknown tokenizer: \x80"
  34. # Additionally test final isalnum() in startsWith().
  35. do_test fts3al-1.3 {
  36. execsql "CREATE VIRTUAL TABLE t3 USING fts3(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. #
  51. # UPDATE: The above is no longer true; there is no such code in fts3.
  52. # But leave the test in just the same.
  53. #
  54. set word "\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80"
  55. set phrase1 "$word $word $word target $word $word $word"
  56. set phrase2 "$word $word $word target $word $word $word"
  57. db eval {CREATE VIRTUAL TABLE t4 USING fts3(content)}
  58. db eval "INSERT INTO t4 (content) VALUES ('$phrase1')"
  59. db eval "INSERT INTO t4 (content) VALUES ('$phrase2')"
  60. do_test fts3al-1.4 {
  61. execsql {SELECT rowid, length(snippet(t4)) FROM t4 WHERE t4 MATCH 'target'}
  62. } {1 241 2 247}
  63. finish_test