fts5colset.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # 2016 August 10
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the FTS5 module.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5colset
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. foreach_detail_mode $::testprefix {
  22. if {[detail_is_none]} continue
  23. do_execsql_test 1.0 {
  24. CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, d, detail=%DETAIL%);
  25. INSERT INTO t1 VALUES('a', 'b', 'c', 'd'); -- 1
  26. INSERT INTO t1 VALUES('d', 'a', 'b', 'c'); -- 2
  27. INSERT INTO t1 VALUES('c', 'd', 'a', 'b'); -- 3
  28. INSERT INTO t1 VALUES('b', 'c', 'd', 'a'); -- 4
  29. }
  30. foreach {tn q res} {
  31. 1 "a" {1 2 3 4}
  32. 2 "{a} : a" {1}
  33. 3 "-{a} : a" {2 3 4}
  34. 4 "- {a c} : a" {2 4}
  35. 5 " - {d d c} : a" {1 2}
  36. 6 "- {d c b a} : a" {}
  37. 7 "-{\"a\"} : b" {1 2 3}
  38. 8 "- c : a" {1 2 4}
  39. 9 "-c : a" {1 2 4}
  40. 10 "-\"c\" : a" {1 2 4}
  41. } {
  42. do_execsql_test 1.$tn {
  43. SELECT rowid FROM t1($q)
  44. } $res
  45. }
  46. foreach {tn q res} {
  47. 0 {{a} : (a AND ":")} {}
  48. 1 "{a b c} : (a AND d)" {2 3}
  49. 2 "{a b c} : (a AND b:d)" {3}
  50. 3 "{a b c} : (a AND d:d)" {}
  51. 4 "{b} : ( {b a} : ( {c b a} : ( {d b c a} : ( d OR c ) ) ) )" {3 4}
  52. 5 "{a} : ( {b a} : ( {c b a} : ( {d b c a} : ( d OR c ) ) ) )" {2 3}
  53. 6 "{a} : ( {b a} : ( {c b} : ( {d b c a} : ( d OR c ) ) ) )" {}
  54. 7 "{a b c} : (b:a AND c:b)" {2}
  55. } {
  56. do_execsql_test 2.$tn {
  57. SELECT rowid FROM t1($q)
  58. } $res
  59. }
  60. foreach {tn w res} {
  61. 0 "a MATCH 'a'" {1}
  62. 1 "b MATCH 'a'" {2}
  63. 2 "b MATCH '{a b c} : a'" {2}
  64. 3 "b MATCH 'a OR b'" {1 2}
  65. 4 "b MATCH 'a OR a:b'" {2}
  66. 5 "b MATCH 'a OR b:b'" {1 2}
  67. } {
  68. do_execsql_test 3.$tn "
  69. SELECT rowid FROM t1 WHERE $w
  70. " $res
  71. }
  72. do_catchsql_test 4.1 {
  73. SELECT * FROM t1 WHERE rowid MATCH 'a'
  74. } {1 {no query solution}}
  75. }
  76. #-------------------------------------------------------------------------
  77. # Confirm that the expression parser creates the same expression tree
  78. # for:
  79. #
  80. # {a b} : (abc AND def)
  81. # -{c d} : (abc AND def)
  82. #
  83. # Assuming that the table columns are (a, b, c, d).
  84. #
  85. do_execsql_test 5.1 {
  86. SELECT fts5_expr('abcd AND cdef');
  87. } {{"abcd" AND "cdef"}}
  88. do_execsql_test 5.2 {
  89. SELECT fts5_expr('{a b} : (abcd AND cdef)', 'a', 'b', 'c', 'd');
  90. } {{{a b} : "abcd" AND {a b} : "cdef"}}
  91. do_execsql_test 5.3 {
  92. SELECT fts5_expr('-{c d} : (abcd AND cdef)', 'a', 'b', 'c', 'd');
  93. } {{{a b} : "abcd" AND {a b} : "cdef"}}
  94. finish_test