fts3tok1.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # 2013 April 22
  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 "fts3tokenize" virtual table
  13. # that is part of the FTS3 module.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. ifcapable !fts3 { finish_test ; return }
  18. set ::testprefix fts3tok1
  19. #-------------------------------------------------------------------------
  20. # Simple test cases. Using the default (simple) tokenizer.
  21. #
  22. do_execsql_test 1.0 {
  23. CREATE VIRTUAL TABLE t1 USING fts3tokenize(simple);
  24. CREATE VIRTUAL TABLE t2 USING fts3tokenize();
  25. CREATE VIRTUAL TABLE t3 USING fts3tokenize(simple, '', 'xyz ');
  26. }
  27. foreach {tn tbl} {1 t1 2 t2 3 t3} {
  28. do_execsql_test 1.$tn.1 "SELECT * FROM $tbl WHERE input = 'one two three'" {
  29. {one two three} one 0 3 0
  30. {one two three} two 4 7 1
  31. {one two three} three 8 13 2
  32. }
  33. do_execsql_test 1.$tn.2 "
  34. SELECT token FROM $tbl WHERE input = 'OnE tWo tHrEe'
  35. " {
  36. one two three
  37. }
  38. }
  39. do_execsql_test 1.4 {
  40. SELECT token FROM t3 WHERE input = '1x2x3x'
  41. } {1 2 3}
  42. do_execsql_test 1.5 {
  43. SELECT token FROM t1 WHERE input = '1x2x3x'
  44. } {1x2x3x}
  45. do_execsql_test 1.6 {
  46. SELECT token FROM t3 WHERE input = '1''2x3x'
  47. } {1'2 3}
  48. do_execsql_test 1.7 {
  49. SELECT token FROM t3 WHERE input = ''
  50. } {}
  51. do_execsql_test 1.8 {
  52. SELECT token FROM t3 WHERE input = NULL
  53. } {}
  54. do_execsql_test 1.9 {
  55. SELECT * FROM t3 WHERE input = 123
  56. } {123 123 0 3 0}
  57. do_execsql_test 1.10 {
  58. SELECT * FROM t1 WHERE input = 'a b c' AND token = 'b';
  59. } {
  60. {a b c} b 2 3 1
  61. }
  62. do_execsql_test 1.11 {
  63. SELECT * FROM t1 WHERE token = 'b' AND input = 'a b c';
  64. } {
  65. {a b c} b 2 3 1
  66. }
  67. do_execsql_test 1.12 {
  68. SELECT * FROM t1 WHERE input < 'b' AND input = 'a b c';
  69. } {
  70. {a b c} a 0 1 0
  71. {a b c} b 2 3 1
  72. {a b c} c 4 5 2
  73. }
  74. do_execsql_test 1.13.1 {
  75. CREATE TABLE c1(x);
  76. INSERT INTO c1(x) VALUES('a b c');
  77. INSERT INTO c1(x) VALUES('d e f');
  78. }
  79. breakpoint
  80. do_execsql_test 1.13.2 {
  81. SELECT * FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid;
  82. } {
  83. {a b c} {a b c} a 0 1 0
  84. {d e f} {d e f} e 2 3 1
  85. }
  86. #-------------------------------------------------------------------------
  87. # Error cases.
  88. #
  89. do_catchsql_test 2.0 {
  90. CREATE VIRTUAL TABLE tX USING fts3tokenize(nosuchtokenizer);
  91. } {1 {unknown tokenizer: nosuchtokenizer}}
  92. do_catchsql_test 2.1 {
  93. CREATE VIRTUAL TABLE t4 USING fts3tokenize;
  94. SELECT * FROM t4;
  95. } {1 {SQL logic error or missing database}}
  96. finish_test