spellfix.test 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # 2012 July 12
  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. set testdir [file dirname $argv0]
  13. source $testdir/tester.tcl
  14. set testprefix spellfix
  15. ifcapable !vtab { finish_test ; return }
  16. load_static_extension db spellfix nextchar
  17. set vocab {
  18. rabbi rabbit rabbits rabble rabid rabies raccoon raccoons race raced racer
  19. racers races racetrack racial racially racing rack racked racket racketeer
  20. racketeering racketeers rackets racking racks radar radars radial radially
  21. radian radiance radiant radiantly radiate radiated radiates radiating radiation
  22. radiations radiator radiators radical radically radicals radices radii radio
  23. radioactive radioastronomy radioed radiography radioing radiology radios radish
  24. radishes radium radius radix radon raft rafter rafters rafts rag rage raged
  25. rages ragged raggedly raggedness raging rags ragweed raid raided raider raiders
  26. raiding raids rail railed railer railers railing railroad railroaded railroader
  27. railroaders railroading railroads rails railway railways raiment rain rainbow
  28. raincoat raincoats raindrop raindrops rained rainfall rainier rainiest raining
  29. rains rainstorm rainy raise raised raiser raisers raises raisin raising rake
  30. raked rakes raking rallied rallies rally rallying ram ramble rambler rambles
  31. rambling ramblings ramification ramifications ramp rampage rampant rampart
  32. ramps ramrod rams ran ranch ranched rancher ranchers ranches ranching rancid
  33. random randomization randomize randomized randomizes randomly randomness randy
  34. rang range ranged rangeland ranger rangers ranges ranging rangy rank ranked
  35. ranker rankers rankest ranking rankings rankle rankly rankness ranks ransack
  36. ransacked ransacking ransacks ransom ransomer ransoming ransoms rant ranted
  37. ranter ranters ranting rants rap rapacious rape raped raper rapes rapid
  38. rapidity rapidly rapids rapier raping rapport rapprochement raps rapt raptly
  39. rapture raptures rapturous rare rarely rareness rarer rarest rarity rascal
  40. rascally rascals rash rasher rashly rashness rasp raspberry rasped rasping
  41. rasps raster rat rate rated rater raters rates rather ratification ratified
  42. ratifies ratify ratifying rating ratings ratio ration rational rationale
  43. rationales rationalities rationality rationalization rationalizations
  44. rationalize rationalized rationalizes rationalizing rationally rationals
  45. rationing rations ratios rats rattle rattled rattler rattlers rattles
  46. rattlesnake rattlesnakes rattling raucous ravage ravaged ravager ravagers
  47. ravages ravaging rave raved raven ravening ravenous ravenously ravens raves
  48. ravine ravines raving ravings raw rawer rawest rawly rawness ray rays raze
  49. razor razors re reabbreviate reabbreviated reabbreviates reabbreviating reach
  50. reachability reachable reachably reached reacher reaches reaching reacquired
  51. react reacted reacting reaction reactionaries reactionary reactions reactivate
  52. reactivated reactivates reactivating reactivation reactive reactively
  53. reactivity reactor reactors reacts read readability readable reader readers
  54. readied readier readies readiest readily readiness reading readings readjusted
  55. readout readouts reads ready readying real realest realign realigned realigning
  56. realigns realism realist realistic realistically realists realities reality
  57. }
  58. do_test 1.1 {
  59. execsql { CREATE VIRTUAL TABLE t1 USING spellfix1 }
  60. foreach word $vocab {
  61. execsql { INSERT INTO t1(word) VALUES($word) }
  62. }
  63. } {}
  64. foreach {tn word res} {
  65. 1 raxpi* {rasping 5 rasped 5 ragweed 5 raspberry 6 rasp 4}
  66. 2 ril* {rail 4 railed 4 railer 4 railers 4 railing 4}
  67. 3 rilis* {realism 6 realist 6 realistic 6 realistically 6 realists 6}
  68. 4 reail* {real 3 realest 3 realign 3 realigned 3 realigning 3}
  69. 5 ras* {rascal 3 rascally 3 rascals 3 rash 3 rasher 3}
  70. 6 realistss* {realists 8 realigns 8 realistic 9 realistically 9 realest 7}
  71. 7 realistss {realists 8 realist 7 realigns 8 realistic 9 realest 7}
  72. 8 rllation* {realities 9 reality 7 rallied 7 railed 4}
  73. 9 renstom* {rainstorm 8 ransom 6 ransomer 6 ransoming 6 ransoms 6}
  74. } {
  75. do_execsql_test 1.2.$tn {
  76. SELECT word, matchlen FROM t1 WHERE word MATCH $word
  77. ORDER BY score, word LIMIT 5
  78. } $res
  79. }
  80. # Tests of the next_char function.
  81. #
  82. do_test 1.10 {
  83. db eval {
  84. CREATE TABLE vocab(w TEXT PRIMARY KEY);
  85. INSERT INTO vocab SELECT word FROM t1;
  86. }
  87. } {}
  88. do_execsql_test 1.11 {
  89. SELECT next_char('re','vocab','w');
  90. } {a}
  91. do_execsql_test 1.11sub {
  92. SELECT next_char('re','(SELECT w AS x FROM vocab)','x');
  93. } {a}
  94. do_execsql_test 1.12 {
  95. SELECT next_char('r','vocab','w');
  96. } {ae}
  97. do_execsql_test 1.13 {
  98. SELECT next_char('','vocab','w');
  99. } {r}
  100. do_test 1.14 {
  101. catchsql {SELECT next_char('','xyzzy','a')}
  102. } {1 {no such table: xyzzy}}
  103. do_execsql_test 1.20 {
  104. CREATE TABLE vocab2(w TEXT);
  105. CREATE INDEX vocab2w ON vocab2(w COLLATE nocase);
  106. INSERT INTO vocab2 VALUES('abc'), ('ABD'), ('aBe'), ('AbF');
  107. SELECT next_char('ab', 'vocab2', 'w', null, 'nocase');
  108. } {cDeF}
  109. do_execsql_test 1.21 {
  110. SELECT next_char('ab','vocab2','w',null,null);
  111. } {c}
  112. do_execsql_test 1.22 {
  113. SELECT next_char('AB','vocab2','w',null,'NOCASE');
  114. } {cDeF}
  115. do_execsql_test 1.23 {
  116. SELECT next_char('ab','vocab2','w',null,'binary');
  117. } {c}
  118. do_execsql_test 2.1 {
  119. CREATE VIRTUAL TABLE t2 USING spellfix1;
  120. INSERT INTO t2 (word, soundslike) VALUES('school', 'skuul');
  121. INSERT INTO t2 (word, soundslike) VALUES('psalm', 'sarm');
  122. SELECT word, matchlen FROM t2 WHERE word MATCH 'sar*' LIMIT 5;
  123. } {psalm 4}
  124. do_execsql_test 2.2 {
  125. SELECT word, matchlen FROM t2 WHERE word MATCH 'skol*' LIMIT 5;
  126. } {school 6}
  127. set vocab {
  128. kangaroo kanji kappa karate keel keeled keeling keels keen keener keenest
  129. keenly keenness keep keeper keepers keeping keeps ken kennel kennels kept
  130. kerchief kerchiefs kern kernel kernels kerosene ketchup kettle
  131. kettles key keyboard keyboards keyed keyhole keying keynote keypad keypads keys
  132. keystroke keystrokes keyword keywords kick kicked kicker kickers kicking
  133. kickoff kicks kid kidded kiddie kidding kidnap kidnapper kidnappers kidnapping
  134. kidnappings kidnaps kidney kidneys kids kill killed killer killers killing
  135. killingly killings killjoy kills kilobit kilobits kiloblock kilobyte kilobytes
  136. kilogram kilograms kilohertz kilohm kilojoule kilometer kilometers kiloton
  137. kilovolt kilowatt kiloword kimono kin kind kinder kindergarten kindest
  138. kindhearted kindle kindled kindles kindling kindly kindness kindred kinds
  139. kinetic king kingdom kingdoms kingly kingpin kings kink kinky kinship kinsman
  140. kiosk kiss kissed kisser kissers kisses kissing kit kitchen kitchenette
  141. kitchens kite kited kites kiting kits kitten kittenish kittens kitty klaxon
  142. kludge kludges klystron knack knapsack knapsacks knave knaves knead kneads knee
  143. kneecap kneed kneeing kneel kneeled kneeling kneels knees knell knells knelt
  144. knew knife knifed knifes knifing knight knighted knighthood knighting knightly
  145. knights knit knits knives knob knobs knock knockdown knocked knocker knockers
  146. knocking knockout knocks knoll knolls knot knots knotted knotting know knowable
  147. knower knowhow knowing knowingly knowledge knowledgeable known knows knuckle
  148. knuckled knuckles koala kosher kudo
  149. }
  150. do_execsql_test 3.1 {
  151. CREATE TABLE costs(iLang, cFrom, cTo, iCost);
  152. INSERT INTO costs VALUES(0, 'a', 'e', 1);
  153. INSERT INTO costs VALUES(0, 'e', 'i', 1);
  154. INSERT INTO costs VALUES(0, 'i', 'o', 1);
  155. INSERT INTO costs VALUES(0, 'o', 'u', 1);
  156. INSERT INTO costs VALUES(0, 'u', 'a', 1);
  157. CREATE VIRTUAL TABLE t3 USING spellfix1(edit_cost_table=costs);
  158. }
  159. do_test 3.2 {
  160. foreach w $vocab {
  161. execsql { INSERT INTO t3(word) VALUES($w) }
  162. }
  163. } {}
  164. foreach {tn word res} {
  165. 1 kos* {kosher 3 kiosk 4 kudo 2 kiss 3 kissed 3}
  166. 2 kellj* {killjoy 5 kill 4 killed 4 killer 4 killers 4}
  167. 3 kellj {kill 4 kills 5 killjoy 7 keel 4 killed 6}
  168. } {
  169. do_execsql_test 3.2.$tn {
  170. SELECT word, matchlen FROM t3 WHERE word MATCH $word
  171. ORDER BY score, word LIMIT 5
  172. } $res
  173. }
  174. do_execsql_test 4.0 {
  175. INSERT INTO t3(command) VALUES('edit_cost_table=NULL');
  176. }
  177. foreach {tn word res} {
  178. 1 kosher {kosher 0 kisser 51 kissers 76 kissed 126 kisses 126}
  179. 2 kellj {keels 60 killjoy 68 kills 80 keel 120 kill 125}
  180. 3 kashar {kosher 80 kisser 91 kissers 116 kissed 166 kisses 166}
  181. } {
  182. do_execsql_test 4.1.$tn {
  183. SELECT word, distance FROM t3 WHERE word MATCH $word
  184. ORDER BY score, word LIMIT 5
  185. } $res
  186. }
  187. do_execsql_test 5.0 {
  188. CREATE TABLE costs2(iLang, cFrom, cTo, iCost);
  189. INSERT INTO costs2 VALUES(0, 'a', 'o', 1);
  190. INSERT INTO costs2 VALUES(0, 'e', 'o', 4);
  191. INSERT INTO costs2 VALUES(0, 'i', 'o', 8);
  192. INSERT INTO costs2 VALUES(0, 'u', 'o', 16);
  193. INSERT INTO t3(command) VALUES('edit_cost_table="costs2"');
  194. }
  195. foreach {tn word res} {
  196. 1 kasher {kosher 1}
  197. 2 kesher {kosher 4}
  198. 3 kisher {kosher 8}
  199. 4 kosher {kosher 0}
  200. 5 kusher {kosher 16}
  201. } {
  202. do_execsql_test 5.1.$tn {
  203. SELECT word, distance FROM t3 WHERE word MATCH $word
  204. ORDER BY score, word LIMIT 1
  205. } $res
  206. }
  207. finish_test