fts5first.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 2017 November 25
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  12. set testprefix fts5first
  13. ifcapable !fts5 {
  14. finish_test
  15. return
  16. }
  17. do_execsql_test 1.0 {
  18. CREATE VIRTUAL TABLE x1 USING fts5(a, b);
  19. }
  20. unset -nocomplain res
  21. foreach {tn expr ok} {
  22. 1 {^abc} 1
  23. 2 {^abc + def} 1
  24. 3 {^ "abc def"} 1
  25. 4 {^"abc def"} 1
  26. 5 {abc ^def} 1
  27. 6 {abc + ^def} 0
  28. 7 {abc ^+ def} 0
  29. 8 {"^abc"} 1
  30. 9 {NEAR(^abc def)} 0
  31. } {
  32. set res(0) {/1 {fts5: syntax error near .*}/}
  33. set res(1) {0 {}}
  34. do_catchsql_test 1.$tn { SELECT * FROM x1($expr) } $res($ok)
  35. }
  36. #-------------------------------------------------------------------------
  37. #
  38. do_execsql_test 2.0 {
  39. INSERT INTO x1 VALUES('a b c', 'b c a');
  40. }
  41. foreach {tn expr match} {
  42. 1 {^a} 1
  43. 2 {^b} 1
  44. 3 {^c} 0
  45. 4 {^a + b} 1
  46. 5 {^b + c} 1
  47. 6 {^c + a} 0
  48. 7 {^"c a"} 0
  49. 8 {a:^a} 1
  50. 9 {a:^b} 0
  51. 10 {a:^"a b"} 1
  52. } {
  53. do_execsql_test 2.$tn { SELECT EXISTS (SELECT rowid FROM x1($expr)) } $match
  54. }
  55. #-------------------------------------------------------------------------
  56. #
  57. do_execsql_test 3.0 {
  58. DELETE FROM x1;
  59. INSERT INTO x1 VALUES('b a', 'c a');
  60. INSERT INTO x1 VALUES('a a', 'c c');
  61. INSERT INTO x1 VALUES('a b', 'a a');
  62. }
  63. fts5_aux_test_functions db
  64. foreach {tn expr expect} {
  65. 1 {^a} {{2 1}}
  66. 2 {^c AND ^b} {{0 2} {1 0}}
  67. } {
  68. do_execsql_test 3.$tn {
  69. SELECT fts5_test_queryphrase(x1) FROM x1($expr) LIMIT 1
  70. } [list $expect]
  71. }
  72. #-------------------------------------------------------------------------
  73. #
  74. do_execsql_test 3.1 {
  75. CREATE VIRTUAL TABLE x2 USING fts5(a, b, c, detail=column);
  76. }
  77. do_catchsql_test 3.2 {
  78. SELECT * FROM x2('a + b');
  79. } {1 {fts5: phrase queries are not supported (detail!=full)}}
  80. do_catchsql_test 3.3 {
  81. SELECT * FROM x2('^a');
  82. } {1 {fts5: phrase queries are not supported (detail!=full)}}
  83. finish_test