Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/spellfix.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / spellfix.test` 483 lines ยท 17303 bytes Raw Blame History 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 13 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 set testprefix spellfix 16 17 ifcapable !vtab { finish_test ; return } 18 19 load_static_extension db spellfix nextchar 20 21 set vocab { 22 rabbi rabbit rabbits rabble rabid rabies raccoon raccoons race raced racer 23 racers races racetrack racial racially racing rack racked racket racketeer 24 racketeering racketeers rackets racking racks radar radars radial radially 25 radian radiance radiant radiantly radiate radiated radiates radiating radiation 26 radiations radiator radiators radical radically radicals radices radii radio 27 radioactive radioastronomy radioed radiography radioing radiology radios radish 28 radishes radium radius radix radon raft rafter rafters rafts rag rage raged 29 rages ragged raggedly raggedness raging rags ragweed raid raided raider raiders 30 raiding raids rail railed railer railers railing railroad railroaded railroader 31 railroaders railroading railroads rails railway railways raiment rain rainbow 32 raincoat raincoats raindrop raindrops rained rainfall rainier rainiest raining 33 rains rainstorm rainy raise raised raiser raisers raises raisin raising rake 34 raked rakes raking rallied rallies rally rallying ram ramble rambler rambles 35 rambling ramblings ramification ramifications ramp rampage rampant rampart 36 ramps ramrod rams ran ranch ranched rancher ranchers ranches ranching rancid 37 random randomization randomize randomized randomizes randomly randomness randy 38 rang range ranged rangeland ranger rangers ranges ranging rangy rank ranked 39 ranker rankers rankest ranking rankings rankle rankly rankness ranks ransack 40 ransacked ransacking ransacks ransom ransomer ransoming ransoms rant ranted 41 ranter ranters ranting rants rap rapacious rape raped raper rapes rapid 42 rapidity rapidly rapids rapier raping rapport rapprochement raps rapt raptly 43 rapture raptures rapturous rare rarely rareness rarer rarest rarity rascal 44 rascally rascals rash rasher rashly rashness rasp raspberry rasped rasping 45 rasps raster rat rate rated rater raters rates rather ratification ratified 46 ratifies ratify ratifying rating ratings ratio ration rational rationale 47 rationales rationalities rationality rationalization rationalizations 48 rationalize rationalized rationalizes rationalizing rationally rationals 49 rationing rations ratios rats rattle rattled rattler rattlers rattles 50 rattlesnake rattlesnakes rattling raucous ravage ravaged ravager ravagers 51 ravages ravaging rave raved raven ravening ravenous ravenously ravens raves 52 ravine ravines raving ravings raw rawer rawest rawly rawness ray rays raze 53 razor razors re reabbreviate reabbreviated reabbreviates reabbreviating reach 54 reachability reachable reachably reached reacher reaches reaching reacquired 55 react reacted reacting reaction reactionaries reactionary reactions reactivate 56 reactivated reactivates reactivating reactivation reactive reactively 57 reactivity reactor reactors reacts read readability readable reader readers 58 readied readier readies readiest readily readiness reading readings readjusted 59 readout readouts reads ready readying real realest realign realigned realigning 60 realigns realism realist realistic realistically realists realities reality 61 } 62 63 do_test 1.1 { 64 execsql { CREATE VIRTUAL TABLE t1 USING spellfix1 } 65 foreach word $vocab { 66 execsql { INSERT INTO t1(word) VALUES($word) } 67 } 68 } {} 69 70 foreach {tn word res} { 71 1 raxpi* {rasping 5 rasped 5 ragweed 5 raspberry 6 rasp 4} 72 2 ril* {rail 4 railed 4 railer 4 railers 4 railing 4} 73 3 rilis* {realism 6 realist 6 realistic 6 realistically 6 realists 6} 74 4 reail* {real 3 realest 3 realign 3 realigned 3 realigning 3} 75 5 ras* {rascal 3 rascally 3 rascals 3 rash 3 rasher 3} 76 6 realistss* {realists 8 realigns 8 realistic 9 realistically 9 realest 7} 77 7 realistss {realists 8 realist 7 realigns 8 realistic 9 realest 7} 78 8 rllation* {realities 9 reality 7 rallied 7 railed 4} 79 9 renstom* {rainstorm 8 ransom 6 ransomer 6 ransoming 6 ransoms 6} 80 } { 81 do_execsql_test 1.2.$tn { 82 SELECT word, matchlen FROM t1 WHERE word MATCH $word 83 ORDER BY score, word LIMIT 5 84 } $res 85 } 86 87 # Tests of the next_char function. 88 # 89 do_test 1.10 { 90 db eval { 91 CREATE TABLE vocab(w TEXT PRIMARY KEY); 92 INSERT INTO vocab SELECT word FROM t1; 93 } 94 } {} 95 do_execsql_test 1.11 { 96 SELECT next_char('re','vocab','w'); 97 } {a} 98 do_execsql_test 1.11sub { 99 SELECT next_char('re','(SELECT w AS x FROM vocab)','x'); 100 } {a} 101 do_execsql_test 1.12 { 102 SELECT next_char('r','vocab','w'); 103 } {ae} 104 do_execsql_test 1.13 { 105 SELECT next_char('','vocab','w'); 106 } {r} 107 do_test 1.14 { 108 catchsql {SELECT next_char('','xyzzy','a')} 109 } {1 {no such table: xyzzy}} 110 111 do_execsql_test 1.20 { 112 CREATE TABLE vocab2(w TEXT); 113 CREATE INDEX vocab2w ON vocab2(w COLLATE nocase); 114 INSERT INTO vocab2 VALUES('abc'), ('ABD'), ('aBe'), ('AbF'); 115 SELECT next_char('ab', 'vocab2', 'w', null, 'nocase'); 116 } {cDeF} 117 do_execsql_test 1.21 { 118 SELECT next_char('ab','vocab2','w',null,null); 119 } {c} 120 do_execsql_test 1.22 { 121 SELECT next_char('AB','vocab2','w',null,'NOCASE'); 122 } {cDeF} 123 do_execsql_test 1.23 { 124 SELECT next_char('ab','vocab2','w',null,'binary'); 125 } {c} 126 127 # Bug 2026-10-29T11:59:57Z: next_char() looped forever under NOCASE 128 # when one of the next characters was "Z", as the characters between 129 # "Z" and "a" sort before "a" in NOCASE order. 130 # 131 do_execsql_test 1.24 { 132 CREATE TABLE vocab3(w TEXT COLLATE NOCASE UNIQUE); 133 INSERT INTO vocab3 VALUES('Zebra'),('zoo'),('apple'),('[x'); 134 SELECT next_char('','vocab3','w'); 135 } {{[aZ}} 136 do_execsql_test 1.25 { 137 SELECT next_char('z','vocab3','w'); 138 } {eo} 139 do_execsql_test 1.26 { 140 CREATE TABLE vocab4(w TEXT UNIQUE); 141 INSERT INTO vocab4 SELECT w FROM vocab3; 142 INSERT INTO vocab4 VALUES('q' || char(`1114111`)), ('q' || char(`1114111`) || 'x'); 143 SELECT next_char('','vocab4','w',null,'nocase'), 144 next_char('','vocab4','w'), 145 next_char('q','vocab4','w') = char(`1114111`); 146 } {{[aqZ} {Z[aqz} 1} 147 148 do_execsql_test 1.30 { 149 SELECT rowid FROM t1 WHERE word='rabbit'; 150 } {2} 151 do_execsql_test 1.31 { 152 UPDATE t1 SET rowid=2000 WHERE word='rabbit'; 153 SELECT rowid FROM t1 WHERE word='rabbit'; 154 } {2000} 155 do_execsql_test 1.32 { 156 INSERT INTO t1(rowid, word) VALUES(3000,'melody'); 157 SELECT rowid, word, matchlen FROM t1 WHERE word MATCH 'melotti' 158 ORDER BY score LIMIT 3; 159 } {3000 melody 6} 160 do_test 1.33 { 161 catchsql {INSERT INTO t1(rowid, word) VALUES(3000,'garden');} 162 } {1 {constraint failed}} 163 164 do_execsql_test 2.1 { 165 CREATE VIRTUAL TABLE t2 USING spellfix1; 166 INSERT INTO t2 (word, soundslike) VALUES('school', 'skuul'); 167 INSERT INTO t2 (word, soundslike) VALUES('psalm', 'sarm'); 168 SELECT word, matchlen FROM t2 WHERE word MATCH 'sar*' LIMIT 5; 169 } {psalm 4} 170 171 do_execsql_test 2.2 { 172 SELECT word, matchlen FROM t2 WHERE word MATCH 'skol*' LIMIT 5; 173 } {school 6} 174 175 set vocab { 176 kangaroo kanji kappa karate keel keeled keeling keels keen keener keenest 177 keenly keenness keep keeper keepers keeping keeps ken kennel kennels kept 178 kerchief kerchiefs kern kernel kernels kerosene ketchup kettle 179 kettles key keyboard keyboards keyed keyhole keying keynote keypad keypads keys 180 keystroke keystrokes keyword keywords kick kicked kicker kickers kicking 181 kickoff kicks kid kidded kiddie kidding kidnap kidnapper kidnappers kidnapping 182 kidnappings kidnaps kidney kidneys kids kill killed killer killers killing 183 killingly killings killjoy kills kilobit kilobits kiloblock kilobyte kilobytes 184 kilogram kilograms kilohertz kilohm kilojoule kilometer kilometers kiloton 185 kilovolt kilowatt kiloword kimono kin kind kinder kindergarten kindest 186 kindhearted kindle kindled kindles kindling kindly kindness kindred kinds 187 kinetic king kingdom kingdoms kingly kingpin kings kink kinky kinship kinsman 188 kiosk kiss kissed kisser kissers kisses kissing kit kitchen kitchenette 189 kitchens kite kited kites kiting kits kitten kittenish kittens kitty klaxon 190 kludge kludges klystron knack knapsack knapsacks knave knaves knead kneads knee 191 kneecap kneed kneeing kneel kneeled kneeling kneels knees knell knells knelt 192 knew knife knifed knifes knifing knight knighted knighthood knighting knightly 193 knights knit knits knives knob knobs knock knockdown knocked knocker knockers 194 knocking knockout knocks knoll knolls knot knots knotted knotting know knowable 195 knower knowhow knowing knowingly knowledge knowledgeable known knows knuckle 196 knuckled knuckles koala kosher kudo 197 } 198 199 do_execsql_test 3.1 { 200 CREATE TABLE costs(iLang, cFrom, cTo, iCost); 201 INSERT INTO costs VALUES(0, 'a', 'e', 1); 202 INSERT INTO costs VALUES(0, 'e', 'i', 1); 203 INSERT INTO costs VALUES(0, 'i', 'o', 1); 204 INSERT INTO costs VALUES(0, 'o', 'u', 1); 205 INSERT INTO costs VALUES(0, 'u', 'a', 1); 206 CREATE VIRTUAL TABLE t3 USING spellfix1(edit_cost_table=costs); 207 } 208 209 do_test 3.2 { 210 foreach w $vocab { 211 execsql { INSERT INTO t3(word) VALUES($w) } 212 } 213 } {} 214 215 foreach {tn word res} { 216 1 kos* {kosher 3 kiosk 4 kudo 2 kiss 3 kissed 3} 217 2 kellj* {killjoy 5 kill 4 killed 4 killer 4 killers 4} 218 3 kellj {kill 4 kills 5 killjoy 7 keel 4 killed 6} 219 } { 220 do_execsql_test 3.2.$tn { 221 SELECT word, matchlen FROM t3 WHERE word MATCH $word 222 ORDER BY score, word LIMIT 5 223 } $res 224 } 225 226 do_execsql_test 4.0 { 227 INSERT INTO t3(command) VALUES('edit_cost_table=NULL'); 228 } 229 foreach {tn word res} { 230 1 kosher {kosher 0 kisser 51 kissers 76 kissed 126 kisses 126} 231 2 kellj {keels 60 killjoy 68 kills 80 keel 120 kill 125} 232 3 kashar {kosher 80 kisser 91 kissers 116 kissed 166 kisses 166} 233 } { 234 do_execsql_test 4.1.$tn { 235 SELECT word, distance FROM t3 WHERE word MATCH $word 236 ORDER BY score, word LIMIT 5 237 } $res 238 } 239 do_execsql_test 5.0 { 240 CREATE TABLE costs2(iLang, cFrom, cTo, iCost); 241 INSERT INTO costs2 VALUES(0, 'a', 'o', 1); 242 INSERT INTO costs2 VALUES(0, 'e', 'o', 4); 243 INSERT INTO costs2 VALUES(0, 'i', 'o', 8); 244 INSERT INTO costs2 VALUES(0, 'u', 'o', 16); 245 INSERT INTO t3(command) VALUES('edit_cost_table="costs2"'); 246 } 247 248 foreach {tn word res} { 249 1 kasher {kosher 1} 250 2 kesher {kosher 4} 251 3 kisher {kosher 8} 252 4 kosher {kosher 0} 253 5 kusher {kosher 16} 254 } { 255 do_execsql_test 5.1.$tn { 256 SELECT word, distance FROM t3 WHERE word MATCH $word 257 ORDER BY score, word LIMIT 1 258 } $res 259 } 260 261 #------------------------------------------------------------------------- 262 # Try some queries by rowid. 263 # 264 do_execsql_test 6.1.1 { 265 SELECT word FROM t3 WHERE rowid = 10; 266 } {keener} 267 do_execsql_test 6.1.2 { 268 SELECT word, distance FROM t3 WHERE rowid = 10; 269 } {keener {}} 270 do_execsql_test 6.1.3 { 271 SELECT word, distance FROM t3 WHERE rowid = 10 AND word MATCH 'kiiner'; 272 } {keener 300} 273 274 ifcapable trace { 275 proc trace_callback {sql} { 276 if {[string range $sql 0 2] == "-- "} { 277 lappend ::trace [string range $sql 3 end] 278 } 279 } 280 281 proc do_tracesql_test {tn sql {res {}}} { 282 set ::trace [list] 283 uplevel [list do_test $tn [subst -nocommands { 284 set vals [execsql {$sql}] 285 concat [set vals] [set ::trace] 286 }] [list {*}$res]] 287 } 288 289 db trace trace_callback 290 do_tracesql_test 6.2.1 { 291 SELECT word FROM t3 WHERE rowid = 10; 292 } {keener 293 {SELECT word, rank, NULL, langid, id FROM "main"."t3_vocab" WHERE rowid=?} 294 } 295 do_tracesql_test 6.2.2 { 296 SELECT word, distance FROM t3 WHERE rowid = 10; 297 } {keener {} 298 {SELECT word, rank, NULL, langid, id FROM "main"."t3_vocab" WHERE rowid=?} 299 } 300 do_tracesql_test 6.2.3 { 301 SELECT word, distance FROM t3 WHERE rowid = 10 AND word MATCH 'kiiner'; 302 } {keener 300 303 {SELECT id, word, rank, coalesce(k1,word) FROM "main"."t3_vocab" WHERE langid=0 AND k2>=?1 AND k20 437 FROM cnt; 438 } {1} 439 440 # Bug 2026-06-23T18:48:40Z 441 # 442 do_execsql_test 8.2 { 443 DROP TABLE IF EXISTS t1; 444 CREATE VIRTUAL TABLE t1 USING spellfix1; 445 INSERT INTO t1(word) VALUES('hello'),('world'); 446 SELECT word FROM t1 WHERE word MATCH ''; 447 } {hello world} 448 449 # Bug 2026-06-26T10:52:36Z 450 # 451 do_execsql_test 8.3 { 452 DROP TABLE t1; 453 CREATE VIRTUAL TABLE t1 USING spellfix1; 454 INSERT INTO t1(command) VALUES('edit_cost_table=''xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); 455 } {} 456 457 458 #------------------------------------------------------------------------- 459 # Check that the next_char() function is not marked SQLITE_INNOCUOUS. 460 # 461 do_execsql_test 9.1 { 462 SELECT (flags & 0x200000) FROM pragma_function_list 463 WHERE name='next_char'; 464 } {0 0 0} 465 466 do_execsql_test 9.2 { 467 CREATE TABLE dict(word); 468 INSERT INTO dict VALUES('cat'), ('car'), ('cow'); 469 CREATE VIEW v1 AS SELECT next_char('c', 'dict', 'word') AS x; 470 PRAGMA trusted_schema = ON; 471 SELECT * FROM v1; 472 } {ao} 473 474 do_catchsql_test 9.3 { 475 PRAGMA trusted_schema = OFF; 476 SELECT * FROM v1; 477 } {1 {unsafe use of next_char()}} 478 479 do_execsql_test 9.4 { 480 PRAGMA trusted_schema = ON; 481 } 482 483 finish_test