fts5tok1.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # 2016 Jan 15
  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. #
  12. source [file join [file dirname [info script]] fts5_common.tcl]
  13. ifcapable !fts5 { finish_test ; return }
  14. set ::testprefix fts5tok1
  15. sqlite3_fts5_register_fts5tokenize db
  16. #-------------------------------------------------------------------------
  17. # Simple test cases. Using the default (ascii) tokenizer.
  18. #
  19. do_execsql_test 1.0 {
  20. CREATE VIRTUAL TABLE t1 USING fts5tokenize(ascii);
  21. CREATE VIRTUAL TABLE t2 USING fts5tokenize();
  22. CREATE VIRTUAL TABLE t3 USING fts5tokenize(
  23. ascii, 'separators', 'xyz', tokenchars, ''''
  24. );
  25. }
  26. foreach {tn tbl} {1 t1 2 t2 3 t3} {
  27. do_execsql_test 1.$tn.1 "SELECT input, * FROM $tbl ('one two three')" {
  28. {one two three} one 0 3 0
  29. {one two three} two 4 7 1
  30. {one two three} three 8 13 2
  31. }
  32. do_execsql_test 1.$tn.2 "
  33. SELECT token FROM $tbl WHERE input = 'OnE tWo tHrEe'
  34. " {
  35. one two three
  36. }
  37. }
  38. do_execsql_test 1.4 {
  39. SELECT token FROM t3 WHERE input = '1x2x3x'
  40. } {1 2 3}
  41. do_execsql_test 1.5 {
  42. SELECT token FROM t1 WHERE input = '1x2x3x'
  43. } {1x2x3x}
  44. do_execsql_test 1.6 {
  45. SELECT token FROM t3 WHERE input = '1''2x3x'
  46. } {1'2 3}
  47. do_execsql_test 1.7 {
  48. SELECT token FROM t3 WHERE input = ''
  49. } {}
  50. do_execsql_test 1.8 {
  51. SELECT token FROM t3 WHERE input = NULL
  52. } {}
  53. do_execsql_test 1.9 {
  54. SELECT input, * FROM t3 WHERE input = 123
  55. } {123 123 0 3 0}
  56. do_execsql_test 1.10 {
  57. SELECT input, * FROM t1 WHERE input = 'a b c' AND token = 'b';
  58. } {
  59. {a b c} b 2 3 1
  60. }
  61. do_execsql_test 1.11 {
  62. SELECT input, * FROM t1 WHERE token = 'b' AND input = 'a b c';
  63. } {
  64. {a b c} b 2 3 1
  65. }
  66. do_execsql_test 1.12 {
  67. SELECT input, * FROM t1 WHERE input < 'b' AND input = 'a b c';
  68. } {
  69. {a b c} a 0 1 0
  70. {a b c} b 2 3 1
  71. {a b c} c 4 5 2
  72. }
  73. do_execsql_test 1.13.1 {
  74. CREATE TABLE c1(x);
  75. INSERT INTO c1(x) VALUES('a b c');
  76. INSERT INTO c1(x) VALUES('d e f');
  77. }
  78. do_execsql_test 1.13.2 {
  79. SELECT c1.*, input, t1.* FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid;
  80. } {
  81. {a b c} {a b c} a 0 1 0
  82. {d e f} {d e f} e 2 3 1
  83. }
  84. #-------------------------------------------------------------------------
  85. # Error cases.
  86. #
  87. do_catchsql_test 2.0 {
  88. CREATE VIRTUAL TABLE tX USING fts5tokenize(nosuchtokenizer);
  89. } {1 {vtable constructor failed: tX}}
  90. do_catchsql_test 2.1 {
  91. CREATE VIRTUAL TABLE t4 USING fts5tokenize;
  92. SELECT * FROM t4;
  93. } {1 {SQL logic error}}
  94. #-------------------------------------------------------------------------
  95. # Embedded 0x00 characters.
  96. #
  97. reset_db
  98. do_execsql_test 3.1.0 {
  99. CREATE VIRTUAL TABLE t1 USING fts5(z);
  100. CREATE VIRTUAL TABLE tt USING fts5vocab(t1, 'instance');
  101. INSERT INTO t1 VALUES('abc' || char(0) || 'def');
  102. SELECT * FROM tt;
  103. } { abc 1 z 0 def 1 z 1 }
  104. do_execsql_test 3.1.1 {
  105. SELECT hex(z) FROM t1;
  106. } {61626300646566}
  107. do_execsql_test 3.1.2 {
  108. INSERT INTO t1(t1) VALUES('integrity-check');
  109. } {}
  110. do_execsql_test 3.2.0 {
  111. CREATE VIRTUAL TABLE t2 USING fts5(z,
  112. tokenize="unicode61 categories 'L* N* Co Cc'"
  113. );
  114. CREATE VIRTUAL TABLE tu USING fts5vocab(t2, 'instance');
  115. INSERT INTO t2 VALUES('abc' || char(0) || 'def');
  116. SELECT * FROM tu;
  117. } { abc 1 z 0 def 1 z 1 }
  118. do_execsql_test 3.2.1 {
  119. SELECT hex(z) FROM t1;
  120. } {61626300646566}
  121. do_execsql_test 3.2.2 {
  122. INSERT INTO t1(t1) VALUES('integrity-check');
  123. } {}
  124. finish_test