fts5auto.test 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. # 2015 May 30
  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. # This file contains automatically generated tests for various types
  13. # of MATCH expressions.
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. set testprefix fts5auto
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. set data {
  23. -4026076
  24. {n x w k b p x b n t t d s} {f j j s p j o}
  25. {w v i y r} {i p y s}
  26. {a o q v e n q r} {q v g u c y a z y}
  27. 3995120
  28. {c} {e e w d t}
  29. {x c p f w r s m l r b f d} {g g u e}
  30. {s n u t d v p d} {b k v p m f}
  31. -2913881
  32. {k m} {a}
  33. {w r j z n s l} {m j i w d t w e l}
  34. {z n c} {v f b m}
  35. 174082
  36. {j} {q l w u k e q v r i}
  37. {j l} {u v w r s p e l}
  38. {p i k j k q c t g u s} {g u y s m h q k g t e s o r}
  39. 3207399
  40. {e t} {}
  41. {p} {y v r b e k h d e v}
  42. {t m w z b g q t s d d h} {o n v u i t o y k j}
  43. 182399
  44. {} {m o s o x d y f a x j z}
  45. {x n z r c d} {n r x i r}
  46. {s v s} {a u}
  47. 768994
  48. {e u t q v z q k j p u f j p} {y c b}
  49. {p s d} {k n w p m p p}
  50. {u o x s d} {f s g r d b d r m m m z y}
  51. 3931037
  52. {c j p x e} {c n k t h z o i}
  53. {} {r r p j k x w q}
  54. {o r d z d} {x}
  55. 3105748
  56. {p x r u} {x i s w o t o g x m z i w}
  57. {q x m z} {h c j w b l y w x c o}
  58. {m b k v} {t v q i s a d x}
  59. -2501642
  60. {o u d n w o m o o s n t r h} {k p e u y p e z d j r y g}
  61. {v b b h d d q y j q j} {a m w d t}
  62. {y e f n} {a k x i x}
  63. -1745680
  64. {z u w j f d b f} {j w i c g u d w e}
  65. {m f p v m a s p v c o s} {s c r z o t w l b e a q}
  66. {m k q} {k b a v o}
  67. -932328
  68. {r v i u m q d r} {f z u v h c m r f g}
  69. {r x r} {k p i d h h w h z u a x}
  70. {k m j p} {h l j a e u c i q x x f x g}
  71. -3923818
  72. {t t p b n u i h e c k} {m z}
  73. {v u d c} {v y y j s g}
  74. {o a f k k q p h g x e n z x} {h d w c o l}
  75. -2145922
  76. {z z l f a l g e d c d h} {j b j p k o o u b q}
  77. {d i g q t f d r h k} {n w g j c x r p t y f l c t}
  78. {d o c u k f o} {r y s x z s p p h g t p y c}
  79. 4552917
  80. {j w j y h l k u} {n a}
  81. {y h w c n k} {b}
  82. {w} {z l r t s i m v c y}
  83. 2292008
  84. {q v q j w y y x u t} {r q z n h a b o}
  85. {d q y} {y v o e j}
  86. {} {a b h c d l p d x}
  87. 1407892
  88. {n j j u q d o a u c f} {r d b w o q n g}
  89. {d e v w s} {v d v o u o x s l s j z y}
  90. {j y w h i f g i h m} {v n z b n y}
  91. -4412544
  92. {g h h r s} {h e r e}
  93. {n q s} {o p z r m l l t}
  94. {p} {f s u o b j}
  95. 1209110
  96. {o a a z t t u h j} {z z i r k r}
  97. {i c x q w g v o x z i z p} {q o g k i n z x e d v w v}
  98. {p f v b g f e d n p u c y k} {q z z a i p a a s r e z}
  99. 3448977
  100. {i v} {l u x t b o k}
  101. {f h u v p} {k a o y j}
  102. {d m k c j} {v c e r u e f i t}
  103. -4703774
  104. {d h v w u z r e h x o l t} {p s f y w y r q d a m w}
  105. {c h g c g j j f t b i c q} {s e}
  106. {c t q j g f} {v n r w y r a g e j d}
  107. 2414151
  108. {s o o s d s k q b f q v p e} {j r o b t o p d l o o x}
  109. {d d k t v e} {}
  110. {t v o d w} {w e q w h y c y y i j b a m}
  111. -3342407
  112. {m c h n e p d o c r w n t} {j d k s p q l}
  113. {t g s r w x j l r z r} {h}
  114. {r q v x i r a n h s} {m y p b v w r a u o g q r}
  115. -993951
  116. {l n p u o j d x t u u c o j} {k r n a r e k v i t o e}
  117. {q f t t a a c z v f} {o n m p v f o e n}
  118. {h z h i p s b j z h} {i t w m k c u g n i}
  119. 1575251
  120. {} {z s i j d o x j a r t}
  121. {h g j u j n v e n z} {p z j n n f}
  122. {s q q f d w r l y i z d o m} {b a n d h t b y g h d}
  123. 4263668
  124. {q g t h f s} {s g x p f q z i s o f l i}
  125. {q k} {w v h a x n a r b}
  126. {m j a h o b i x k r w z q u} {m t r g j o e q t m p u l}
  127. 2487819
  128. {m w g x r n e u t s r} {b x a t u u j c r n}
  129. {j} {w f j r e e y l p}
  130. {o u h b} {o c a c a b v}
  131. 167966
  132. {o d b s d o a u m o x y} {c}
  133. {r w d o b v} {z e b}
  134. {i n z a f g z o} {m u b a g}
  135. 1948599
  136. {n r g q d j s} {n k}
  137. {l b p d v t k h y y} {u m k e c}
  138. {t b n y o t b} {j w c i r x x}
  139. 2941631
  140. {l d p l b g f} {e k e}
  141. {p j} {m c s w t b k n l d x}
  142. {f o v y v l} {c w p s w j w c u t y}
  143. 3561104
  144. {d r j j r j i g p} {u}
  145. {g r j q} {z l p d s n f c h t d c v z}
  146. {w r c f s x z y} {g f o k g g}
  147. -2223281
  148. {y e t j j z f p o m m z} {h k o g o}
  149. {m x a t} {l q x l}
  150. {r w k d l s y b} {q g k b}
  151. -4502874
  152. {k k b x k l f} {r}
  153. {} {q m z b k h k u n e z}
  154. {z q g y m y u} {}
  155. 1757599
  156. {d p z j y u r} {z p l q w j t j}
  157. {n i r x r y j} {}
  158. {h} {w t d q c x z z x e e}
  159. -4809589
  160. {} {z p x u h i i n g}
  161. {w q s u d b f x n} {l y k b b r x t i}
  162. {n d v j q o t o d p z e} {u r y u v u c}
  163. 1068408
  164. {y e} {e g s k e w t p v o b k}
  165. {z c m s} {r u r u h n h b p q g b}
  166. {j k b l} {m c d t s r s q a d b o f}
  167. -1972554
  168. {m s w} {d k v s a r k p a r i v}
  169. {g j z k p} {y k c v r e u o q f i b a}
  170. {i p i} {c z w c y b n z i v}
  171. -2052385
  172. {} {x e u f f g n c i x n e i e}
  173. {} {p s w d x p g}
  174. {} {s j a h n}
  175. 2805981
  176. {m x g c w o e} {k g u y r y i u e g g}
  177. {f k j v t x p h x k u} {w i}
  178. {b l f z f v t n} {i u d o d p h s m u}
  179. 2507621
  180. {} {u b n l x f n j t}
  181. {u r x l h} {h r l m r}
  182. {d y e n b s q v t k n q q} {x l t v w h a s k}
  183. -3138375
  184. {e o f j y x u w v e w z} {r d q g k n n v r c z n e w}
  185. {l y i q z k j p u f q s k} {c i l l i m a a g a z r x f}
  186. {a v k h m q z b y n z} {q g w c y r r o a}
  187. -457971
  188. {j x a w e c s h f l f} {q}
  189. {j f v j u m d q r v v} {x n v a w}
  190. {i e h d h f u w t t z} {v s u l s v o v i k n e}
  191. 2265221
  192. {z t c y w n y r t} {n b a x s}
  193. {q w a v} {a b s d x i g w t e z h}
  194. {t l} {j k r w f f y j o k u}
  195. -3941280
  196. {r x t o z} {f j n z k}
  197. {t x e b t d b k w i s} {j t y h i h}
  198. {y q g n g s u v c z j z n g} {n n g t l p h}
  199. 2084745
  200. {z d z d} {j}
  201. {o e k t b k a z l w} {o p i h k c x}
  202. {c r b t i j f} {z e n m}
  203. 1265843
  204. {} {j s g j j x u y}
  205. {u q t f} {g o g}
  206. {w o j e d} {w q n a c t q x j}
  207. -2941116
  208. {i n c u o} {f b}
  209. {o m s q d o z a q} {f s v o b b}
  210. {o a z c h r} {j e w h b f z}
  211. -1265441
  212. {p g z q v a o a x a} {s t h}
  213. {w i p o c} {s n d g f z w q o d v v l j}
  214. {y f b i a s v} {u m o z k k s t s d p b l p}
  215. -1989158
  216. {r i c n} {r e w w i n z}
  217. {q u s y b w u g y g f o} {y}
  218. {d} {j x i b x u y d c p v a h}
  219. 2391989
  220. {b n w x w f q h p i} {e u b b i n a i o c d g}
  221. {v a z o i e n l x l r} {r u f o r k w m d w}
  222. {k s} {r f e j q p w}
  223. }
  224. do_execsql_test 1.0 {
  225. CREATE VIRTUAL TABLE tt USING fts5(a, b, c, d, e, f);
  226. } {}
  227. fts5_aux_test_functions db
  228. proc do_auto_test {tn tbl expr} {
  229. foreach order {asc desc} {
  230. set res [fts5_poslist_data $expr $tbl $order]
  231. set testname "$tn.[string range $order 0 0].rows=[expr [llength $res]/2]"
  232. set ::autotest_expr $expr
  233. do_execsql_test $testname [subst -novar {
  234. SELECT rowid, fts5_test_poslist([set tbl]) FROM [set tbl]
  235. WHERE [set tbl] MATCH $::autotest_expr ORDER BY rowid [set order]
  236. }] $res
  237. }
  238. }
  239. #-------------------------------------------------------------------------
  240. #
  241. for {set fold 0} {$fold < 3} {incr fold} {
  242. switch $fold {
  243. 0 { set map {} }
  244. 1 { set map {
  245. a a b a c b d b e c f c g d h d
  246. i e j e k f l f m g g g o h p h
  247. q i r i s j t j u k v k w l x l
  248. y m z m
  249. }}
  250. 2 { set map {
  251. a a b a c a d a e a f a g a h a
  252. i b j b k b l b m b g b o b p b
  253. q c r c s c t c u c v c w c x c
  254. }}
  255. }
  256. execsql {
  257. BEGIN;
  258. DELETE FROM tt;
  259. }
  260. foreach {rowid a b c d e f} [string map $map $data] {
  261. if {$rowid==-4703774} {
  262. execsql {
  263. INSERT INTO tt(rowid, a, b, c, d, e, f)
  264. VALUES($rowid, $a, $b, $c, $d, $e, $f)
  265. }
  266. }
  267. }
  268. execsql COMMIT
  269. foreach {tn expr} {
  270. A.1 { {a} : x }
  271. A.2 { {a b} : x }
  272. A.3 { {a b f} : x }
  273. A.4 { {f a b} : x }
  274. A.5 { {f a b} : x y }
  275. A.6 { {f a b} : x + y }
  276. A.7 { {c a b} : x + c }
  277. A.8 { {c d} : "l m" }
  278. A.9 { {c e} : "l m" }
  279. A.10 { {a b c a b c a b c f f e} : "l m" }
  280. B.1 { a NOT b }
  281. B.2 { a NOT a:b }
  282. B.3 { a OR (b AND c) }
  283. B.4 { a OR (b AND {a b c}:c) }
  284. B.5 { a OR "b c" }
  285. B.6 { a OR b OR c }
  286. C.1 { a OR (b AND "b c") }
  287. C.2 { a OR (b AND "z c") }
  288. } {
  289. do_auto_test 3.$fold.$tn tt $expr
  290. }
  291. }
  292. proc replace_elems {list args} {
  293. set ret $list
  294. foreach {idx elem} $args {
  295. set ret [lreplace $ret $idx $idx $elem]
  296. }
  297. set ret
  298. }
  299. #-------------------------------------------------------------------------
  300. #
  301. set bigdoc [string trim [string repeat "a " 1000]]
  302. do_test 4.0 {
  303. set a [replace_elems $bigdoc 50 x 950 x]
  304. set b [replace_elems $bigdoc 20 y 21 x 887 x 888 y]
  305. set c [replace_elems $bigdoc 1 z 444 z 789 z]
  306. execsql {
  307. CREATE VIRTUAL TABLE yy USING fts5(c1, c2, c3);
  308. INSERT INTO yy(rowid, c1, c2, c3) VALUES(-56789, $a, $b, $c);
  309. INSERT INTO yy(rowid, c1, c2, c3) VALUES(250, $a, $b, $c);
  310. }
  311. } {}
  312. foreach {tn expr} {
  313. 1 x
  314. 2 y
  315. 3 z
  316. 4 {c1 : x} 5 {c2 : x} 6 {c3 : x}
  317. 7 {c1 : y} 8 {c2 : y} 9 {c3 : y}
  318. 10 {c1 : z} 11 {c2 : z} 12 {c3 : z}
  319. } {
  320. do_auto_test 4.$tn yy $expr
  321. }
  322. finish_test