fts5query.test 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # 2015 October 27
  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 fts5query
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. for {set tn 1 ; set pgsz 64} {$tn<32} {incr tn; incr pgsz 16} {
  22. reset_db
  23. do_test 1.$tn.1 {
  24. execsql {
  25. CREATE VIRTUAL TABLE t1 USING fts5(x);
  26. INSERT INTO t1(t1, rank) VALUES('pgsz', $pgsz);
  27. BEGIN;
  28. }
  29. foreach x [list aaa bbb ccc ddd eee fff ggg hhh iii jjj] {
  30. set doc [string repeat "$x " 30]
  31. execsql { INSERT INTO t1 VALUES($doc) }
  32. }
  33. execsql COMMIT
  34. } {}
  35. do_execsql_test 1.$tn.2 {
  36. INSERT INTO t1(t1) VALUES('integrity-check');
  37. }
  38. set ret 1
  39. foreach x [list a b c d e f g h i j] {
  40. do_execsql_test 1.$tn.3.$ret {
  41. SELECT rowid FROM t1 WHERE t1 MATCH $x || '*';
  42. } $ret
  43. incr ret
  44. }
  45. }
  46. for {set tn 1 ; set pgsz 64} {$tn<32} {incr tn; incr pgsz 16} {
  47. reset_db
  48. do_test 2.$tn.1 {
  49. execsql {
  50. CREATE VIRTUAL TABLE t1 USING fts5(x);
  51. INSERT INTO t1(t1, rank) VALUES('pgsz', $pgsz);
  52. BEGIN;
  53. }
  54. foreach x [list bbb ddd fff hhh jjj lll nnn ppp rrr ttt] {
  55. set doc [string repeat "$x " 30]
  56. execsql { INSERT INTO t1 VALUES($doc) }
  57. }
  58. execsql COMMIT
  59. } {}
  60. do_execsql_test 2.$tn.2 {
  61. INSERT INTO t1(t1) VALUES('integrity-check');
  62. }
  63. set ret 1
  64. foreach x [list a c e g i k m o q s u] {
  65. do_execsql_test 2.$tn.3.$ret {
  66. SELECT rowid FROM t1 WHERE t1 MATCH $x || '*';
  67. } {}
  68. incr ret
  69. }
  70. }
  71. reset_db
  72. do_execsql_test 3.0 {
  73. CREATE VIRTUAL TABLE x1 USING fts5(a);
  74. INSERT INTO x1(rowid, a) VALUES(-1000000000000, 'toyota');
  75. INSERT INTO x1(rowid, a) VALUES(1, 'tarago');
  76. }
  77. do_execsql_test 3.1 {
  78. SELECT rowid FROM x1('t*');
  79. } {-1000000000000 1}
  80. finish_test