fts5eb.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # 2014 June 17
  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. #
  12. source [file join [file dirname [info script]] fts5_common.tcl]
  13. set testprefix fts5eb
  14. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  15. ifcapable !fts5 {
  16. finish_test
  17. return
  18. }
  19. proc do_syntax_error_test {tn expr err} {
  20. set ::se_expr $expr
  21. do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
  22. }
  23. proc do_syntax_test {tn expr res} {
  24. set ::se_expr $expr
  25. do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
  26. }
  27. foreach {tn expr res} {
  28. 1 {abc} {"abc"}
  29. 2 {abc ""} {"abc"}
  30. 3 {""} {}
  31. 4 {abc OR ""} {"abc" OR ""}
  32. 5 {abc NOT ""} {"abc" NOT ""}
  33. 6 {abc AND ""} {"abc" AND ""}
  34. 7 {"" OR abc} {"" OR "abc"}
  35. 8 {"" NOT abc} {"" NOT "abc"}
  36. 9 {"" AND abc} {"" AND "abc"}
  37. 10 {abc + "" + def} {"abc" + "def"}
  38. 11 {abc "" def} {"abc" AND "def"}
  39. 12 {r+e OR w} {"r" + "e" OR "w"}
  40. 13 {a AND b NOT c} {"a" AND ("b" NOT "c")}
  41. 14 {a OR b NOT c} {"a" OR ("b" NOT "c")}
  42. 15 {a NOT b AND c} {("a" NOT "b") AND "c"}
  43. 16 {a NOT b OR c} {("a" NOT "b") OR "c"}
  44. 17 {a AND b OR c} {("a" AND "b") OR "c"}
  45. 18 {a OR b AND c} {"a" OR ("b" AND "c")}
  46. } {
  47. do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
  48. }
  49. do_catchsql_test 2.1 {
  50. SELECT fts5_expr()
  51. } {1 {wrong number of arguments to function fts5_expr}}
  52. do_catchsql_test 2.2 {
  53. SELECT fts5_expr_tcl()
  54. } {1 {wrong number of arguments to function fts5_expr_tcl}}
  55. do_catchsql_test 2.3 {
  56. SELECT fts5_expr('')
  57. } {1 {fts5: syntax error near ""}}
  58. do_catchsql_test 2.4 {
  59. SELECT fts5_expr(NULL)
  60. } {1 {fts5: syntax error near ""}}
  61. do_catchsql_test 2.5 {
  62. SELECT fts5_expr(NULL, NULL)
  63. } {1 {parse error in ""}}
  64. for {set i 0} {$i < 255} {incr i} {
  65. do_test 2.6.$i {
  66. lindex [catchsql {sELECT fts5_expr(NULL, char($i));}] 0
  67. } 1
  68. }
  69. do_execsql_test 3.0 {
  70. CREATE VIRTUAL TABLE e1 USING fts5(text, tokenize = 'porter unicode61');
  71. INSERT INTO e1 VALUES ('just a few words with a / inside');
  72. }
  73. do_execsql_test 3.1 {
  74. SELECT rowid, format('%g',bm25(e1)) FROM e1 WHERE e1 MATCH '"just"' ORDER BY rank;
  75. } {1 -1e-06}
  76. do_execsql_test 3.2 {
  77. SELECT rowid FROM e1 WHERE e1 MATCH '"/" OR "just"'
  78. } 1
  79. do_execsql_test 3.3 {
  80. SELECT rowid, format('%g',bm25(e1)) FROM e1 WHERE e1 MATCH '"/" OR "just"' ORDER BY rank;
  81. } {1 -1e-06}
  82. do_execsql_test 3.4 "
  83. SELECT fts5_expr_tcl('e AND \" \"');
  84. " {{AND [nearset -- {e}] [{}]}}
  85. finish_test