fts5ea.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. # Test the fts5 expression parser directly using the fts5_expr() SQL
  13. # test function.
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. set testprefix fts5ea
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. proc do_syntax_error_test {tn expr err} {
  23. set ::se_expr $expr
  24. do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
  25. }
  26. proc do_syntax_test {tn expr res} {
  27. set ::se_expr $expr
  28. do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
  29. }
  30. foreach {tn expr res} {
  31. 1 {abc} {"abc"}
  32. 2 {abc def} {"abc" AND "def"}
  33. 3 {abc*} {"abc" *}
  34. 4 {"abc def ghi" *} {"abc" + "def" + "ghi" *}
  35. 5 {one AND two} {"one" AND "two"}
  36. 6 {one+two} {"one" + "two"}
  37. 7 {one AND two OR three} {("one" AND "two") OR "three"}
  38. 8 {one OR two AND three} {"one" OR ("two" AND "three")}
  39. 9 {NEAR(one two)} {NEAR("one" "two", 10)}
  40. 10 {NEAR("one three"* two, 5)} {NEAR("one" + "three" * "two", 5)}
  41. 11 {a OR b NOT c} {"a" OR ("b" NOT "c")}
  42. 12 "\x20one\x20two\x20three" {"one" AND "two" AND "three"}
  43. 13 "\x09one\x0Atwo\x0Dthree" {"one" AND "two" AND "three"}
  44. 14 {"abc""def"} {"abc" + "def"}
  45. } {
  46. do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
  47. }
  48. foreach {tn expr res} {
  49. 1 {c1:abc}
  50. {c1 : "abc"}
  51. 2 {c2 : NEAR(one two) c1:"hello world"}
  52. {c2 : NEAR("one" "two", 10) AND c1 : "hello" + "world"}
  53. } {
  54. do_execsql_test 2.$tn {SELECT fts5_expr($expr, 'c1', 'c2')} [list $res]
  55. }
  56. foreach {tn expr err} {
  57. 1 {AND} {fts5: syntax error near "AND"}
  58. 2 {abc def AND} {fts5: syntax error near ""}
  59. 3 {abc OR AND} {fts5: syntax error near "AND"}
  60. 4 {(a OR b) abc} {fts5: syntax error near "abc"}
  61. 5 {NEaR (a b)} {fts5: syntax error near "NEaR"}
  62. 6 {NEa (a b)} {fts5: syntax error near "NEa"}
  63. 7 {(a OR b) NOT c)} {fts5: syntax error near ")"}
  64. 8 {nosuch: a nosuch2: b} {no such column: nosuch}
  65. 9 {addr: a nosuch2: b} {no such column: nosuch2}
  66. 10 {NOT} {fts5: syntax error near "NOT"}
  67. 11 {a AND "abc} {unterminated string}
  68. 12 {NEAR(a b, xyz)} {expected integer, got "xyz"}
  69. 13 {NEAR(a b, // )} {fts5: syntax error near "/"}
  70. 14 {NEAR(a b, "xyz" )} {expected integer, got ""xyz""}
  71. } {
  72. do_catchsql_test 3.$tn {SELECT fts5_expr($expr, 'name', 'addr')} [list 1 $err]
  73. }
  74. #-------------------------------------------------------------------------
  75. # Experiment with a tokenizer that considers " to be a token character.
  76. #
  77. do_execsql_test 4.0 {
  78. SELECT fts5_expr('a AND """"', 'x', 'tokenize="unicode61 tokenchars ''""''"');
  79. } {{"a" AND """"}}
  80. #-------------------------------------------------------------------------
  81. # Experiment with a tokenizer that considers " to be a token character.
  82. #
  83. do_catchsql_test 5.0 {
  84. SELECT fts5_expr('abc | def');
  85. } {1 {fts5: syntax error near "|"}}
  86. finish_test