fts5multi.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # 2014 September 13
  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 fts5multi
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. fts5_aux_test_functions db
  22. do_execsql_test 1.0 {
  23. CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
  24. INSERT INTO t1 VALUES('gg bb bb' ,'gg ff gg' ,'ii ii');
  25. INSERT INTO t1 VALUES('dd dd hh kk','jj' ,'aa');
  26. INSERT INTO t1 VALUES('kk gg ee' ,'hh cc' ,'hh jj aa cc');
  27. INSERT INTO t1 VALUES('hh' ,'bb jj cc' ,'kk ii');
  28. INSERT INTO t1 VALUES('kk dd kk ii','aa ee aa' ,'ee');
  29. INSERT INTO t1 VALUES('ee' ,'ff gg kk aa','ee ff ee');
  30. INSERT INTO t1 VALUES('ff jj' ,'gg ee' ,'kk ee gg kk');
  31. INSERT INTO t1 VALUES('ff ee dd hh','kk ee' ,'gg dd');
  32. INSERT INTO t1 VALUES('bb' ,'aa' ,'bb aa');
  33. INSERT INTO t1 VALUES('hh cc bb' ,'ff bb' ,'cc');
  34. INSERT INTO t1 VALUES('jj' ,'ff dd bb aa','dd dd ff ff');
  35. INSERT INTO t1 VALUES('ff dd gg dd','gg aa bb ff','cc');
  36. INSERT INTO t1 VALUES('ff aa cc jj','kk' ,'ii dd');
  37. INSERT INTO t1 VALUES('jj dd' ,'cc' ,'ii hh ee aa');
  38. INSERT INTO t1 VALUES('ff ii hh' ,'dd' ,'gg');
  39. INSERT INTO t1 VALUES('ff dd gg hh','hh' ,'ff dd');
  40. INSERT INTO t1 VALUES('cc cc' ,'ff dd ff' ,'bb');
  41. INSERT INTO t1 VALUES('ii' ,'bb ii' ,'jj kk');
  42. INSERT INTO t1 VALUES('ff hh' ,'hh bb' ,'bb dd ee');
  43. INSERT INTO t1 VALUES('jj kk' ,'jj' ,'gg ff cc');
  44. INSERT INTO t1 VALUES('dd kk' ,'ii gg' ,'dd');
  45. INSERT INTO t1 VALUES('cc' ,'aa ff' ,'ii');
  46. INSERT INTO t1 VALUES('bb ff bb ii','bb kk bb aa','hh ff ii dd');
  47. INSERT INTO t1 VALUES('aa' ,'ee bb jj jj','dd');
  48. INSERT INTO t1 VALUES('kk dd cc' ,'aa jj' ,'ee aa ff');
  49. INSERT INTO t1 VALUES('aa gg aa' ,'jj' ,'ii kk hh gg');
  50. INSERT INTO t1 VALUES('ff hh aa' ,'jj ii' ,'hh dd bb jj');
  51. INSERT INTO t1 VALUES('hh' ,'aa gg kk' ,'bb ee');
  52. INSERT INTO t1 VALUES('bb' ,'ee' ,'gg');
  53. INSERT INTO t1 VALUES('dd kk' ,'kk bb aa' ,'ee');
  54. }
  55. foreach {tn c1 e1 c2 e2} {
  56. 1 t1 aa t1 bb
  57. 2 a aa b bb
  58. 3 a "aa OR bb OR cc" b "jj OR ii OR hh"
  59. 4 t1 "aa AND bb" t1 "cc"
  60. 5 c "kk" b "aa OR bb OR cc OR dd OR ee"
  61. } {
  62. if {$c1=="t1"} {
  63. set lhs "( $e1 )"
  64. } else {
  65. set lhs "$c1 : ( $e1 )"
  66. }
  67. if {$c2=="t1"} {
  68. set rhs "( $e2 )"
  69. } else {
  70. set rhs "$c2 : ( $e2 )"
  71. }
  72. set q1 "t1 MATCH '($lhs) AND ($rhs)'"
  73. set q2 "$c1 MATCH '$e1' AND $c2 MATCH '$e2'"
  74. set ret [execsql "SELECT rowid FROM t1 WHERE $q1"]
  75. set N [llength $ret]
  76. do_execsql_test 1.$tn.1.($N) "SELECT rowid FROM t1 WHERE $q2" $ret
  77. set ret [execsql "SELECT fts5_test_poslist(t1) FROM t1 WHERE $q1"]
  78. do_execsql_test 1.$tn.2.($N) "
  79. SELECT fts5_test_poslist(t1) FROM t1 WHERE $q2
  80. " $ret
  81. }
  82. do_catchsql_test 2.1.1 {
  83. SELECT rowid FROM t1 WHERE t1 MATCH '(NOT' AND t1 MATCH 'aa bb';
  84. } {1 {fts5: syntax error near "NOT"}}
  85. do_catchsql_test 2.1.2 {
  86. SELECT rowid FROM t1 WHERE t1 MATCH 'aa bb' AND t1 MATCH '(NOT';
  87. } {1 {fts5: syntax error near "NOT"}}
  88. finish_test