OLD | NEW |
(Empty) | |
| 1 # 2014 November 24 |
| 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 # Specifically, the auxiliary function "highlight". |
| 15 # |
| 16 |
| 17 source [file join [file dirname [info script]] fts5_common.tcl] |
| 18 set testprefix fts5ak |
| 19 |
| 20 # If SQLITE_ENABLE_FTS5 is defined, omit this file. |
| 21 ifcapable !fts5 { |
| 22 finish_test |
| 23 return |
| 24 } |
| 25 |
| 26 do_execsql_test 1.1 { |
| 27 CREATE VIRTUAL TABLE ft1 USING fts5(x); |
| 28 INSERT INTO ft1 VALUES('i d d a g i b g d d'); |
| 29 INSERT INTO ft1 VALUES('h d b j c c g a c a'); |
| 30 INSERT INTO ft1 VALUES('e j a e f h b f h h'); |
| 31 INSERT INTO ft1 VALUES('j f h d g h i b d f'); |
| 32 INSERT INTO ft1 VALUES('d c j d c j b c g e'); |
| 33 INSERT INTO ft1 VALUES('i a d e g j g d a a'); |
| 34 INSERT INTO ft1 VALUES('j f c e d a h j d b'); |
| 35 INSERT INTO ft1 VALUES('i c c f a d g h j e'); |
| 36 INSERT INTO ft1 VALUES('i d i g c d c h b f'); |
| 37 INSERT INTO ft1 VALUES('g d a e h a b c f j'); |
| 38 } |
| 39 |
| 40 do_execsql_test 1.2 { |
| 41 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e'; |
| 42 } { |
| 43 {[e] j a [e] f h b f h h} |
| 44 {d c j d c j b c g [e]} |
| 45 {i a d [e] g j g d a a} |
| 46 {j f c [e] d a h j d b} |
| 47 {i c c f a d g h j [e]} |
| 48 {g d a [e] h a b c f j} |
| 49 } |
| 50 |
| 51 do_execsql_test 1.3 { |
| 52 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'h + d'; |
| 53 } { |
| 54 {[h d] b j c c g a c a} |
| 55 {j f [h d] g h i b d f} |
| 56 } |
| 57 |
| 58 do_execsql_test 1.4 { |
| 59 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d'; |
| 60 } { |
| 61 {i [d d] a g i b g [d d]} |
| 62 } |
| 63 |
| 64 do_execsql_test 1.5 { |
| 65 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e e e' |
| 66 } { |
| 67 {[e] j a [e] f h b f h h} |
| 68 {d c j d c j b c g [e]} |
| 69 {i a d [e] g j g d a a} |
| 70 {j f c [e] d a h j d b} |
| 71 {i c c f a d g h j [e]} |
| 72 {g d a [e] h a b c f j} |
| 73 } |
| 74 |
| 75 do_execsql_test 1.6 { |
| 76 SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d d + d'; |
| 77 } { |
| 78 {i [d d] a g i b g [d d]} |
| 79 } |
| 80 |
| 81 do_execsql_test 2.1 { |
| 82 CREATE VIRTUAL TABLE ft2 USING fts5(x); |
| 83 INSERT INTO ft2 VALUES('a b c d e f g h i j'); |
| 84 } |
| 85 |
| 86 do_execsql_test 2.2 { |
| 87 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c+d+e' |
| 88 } {{a [b c d e] f g h i j}} |
| 89 |
| 90 do_execsql_test 2.3 { |
| 91 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d e+f+g' |
| 92 } { |
| 93 {a [b c d] [e f g] h i j} |
| 94 } |
| 95 |
| 96 do_execsql_test 2.4 { |
| 97 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c' |
| 98 } { |
| 99 {a [b c d] e f g h i j} |
| 100 } |
| 101 |
| 102 do_execsql_test 2.5 { |
| 103 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c c+d+e' |
| 104 } { |
| 105 {a [b c d e] f g h i j} |
| 106 } |
| 107 |
| 108 do_execsql_test 2.6.1 { |
| 109 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'f d' |
| 110 } { |
| 111 {a b c [d] e [f] g h i j} |
| 112 } |
| 113 |
| 114 do_execsql_test 2.6.2 { |
| 115 SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'd f' |
| 116 } { |
| 117 {a b c [d] e [f] g h i j} |
| 118 } |
| 119 |
| 120 #------------------------------------------------------------------------- |
| 121 # The example from the docs. |
| 122 # |
| 123 do_execsql_test 3.1 { |
| 124 -- Assuming this: |
| 125 CREATE VIRTUAL TABLE ft USING fts5(a); |
| 126 INSERT INTO ft VALUES('a b c x c d e'); |
| 127 INSERT INTO ft VALUES('a b c c d e'); |
| 128 INSERT INTO ft VALUES('a b c d e'); |
| 129 |
| 130 -- The following SELECT statement returns these three rows: |
| 131 -- '[a b c] x [c d e]' |
| 132 -- '[a b c] [c d e]' |
| 133 -- '[a b c d e]' |
| 134 SELECT highlight(ft, 0, '[', ']') FROM ft WHERE ft MATCH 'a+b+c AND c+d+e'; |
| 135 } { |
| 136 {[a b c] x [c d e]} |
| 137 {[a b c] [c d e]} |
| 138 {[a b c d e]} |
| 139 } |
| 140 |
| 141 |
| 142 finish_test |
| 143 |
OLD | NEW |