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 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15set testprefix spellfix2 16 17ifcapable !vtab { finish_test ; return } 18load_static_extension db spellfix nextchar 19 20do_execsql_test 1.0 { 21 CREATE VIRTUAL TABLE demo USING spellfix1; 22 INSERT INTO demo(word) VALUES ('amsterdam'); 23 INSERT INTO demo(word) VALUES ('amsterdammetje'); 24 INSERT INTO demo(word) VALUES ('amsterdamania'); 25 INSERT INTO demo(word) VALUES ('amsterdamweg'); 26 INSERT INTO demo(word) VALUES ('amsterdamsestraat'); 27 INSERT INTO demo(word) VALUES ('amsterdamlaan'); 28} 29 30do_execsql_test 1.1 { 31 SELECT word, distance, matchlen FROM demo 32 WHERE word MATCH 'amstedam*' AND top=3 33 ORDER BY +word; 34} { 35 amsterdam 100 9 36 amsterdamania 100 9 37 amsterdammetje 100 9 38} 39 40do_execsql_test 1.2 { 41 SELECT word, distance, matchlen FROM demo WHERE 42 word MATCH 'amstedam*' AND top=3 AND distance <= 100 43 ORDER BY +word; 44} { 45 amsterdam 100 9 46 amsterdamania 100 9 47 amsterdammetje 100 9 48} 49 50do_execsql_test 1.3 { 51 SELECT word, distance, matchlen FROM demo WHERE 52 word MATCH 'amstedam*' AND distance <= 100 53 ORDER BY +word; 54} { 55 amsterdam 100 9 56 amsterdamania 100 9 57 amsterdamlaan 100 9 58 amsterdammetje 100 9 59 amsterdamsestraat 100 9 60 amsterdamweg 100 9 61} 62 63do_test 1.4 { 64 foreach l {a b c d e f g h i j k l m n o p q r s t u v w x y z} { 65 execsql { INSERT INTO demo(word) VALUES ('amsterdam' || $l) } 66 } 67} {} 68 69do_execsql_test 1.5 { 70 SELECT count(*) FROM demo WHERE word MATCH 'amstedam*' AND distance <= 100; 71 SELECT count(*) FROM demo 72 WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20; 73} { 74 32 20 75} 76 77do_execsql_test 1.6 { 78 SELECT word, distance, matchlen FROM demo 79 WHERE word MATCH 'amstedam*' AND distance <= 100 80 ORDER BY distance, word; 81} { 82 amsterdam 100 9 amsterdama 100 9 83 amsterdamania 100 9 amsterdamb 100 9 84 amsterdamc 100 9 amsterdamd 100 9 85 amsterdame 100 9 amsterdamf 100 9 86 amsterdamg 100 9 amsterdamh 100 9 87 amsterdami 100 9 amsterdamj 100 9 88 amsterdamk 100 9 amsterdaml 100 9 89 amsterdamlaan 100 9 amsterdamm 100 9 90 amsterdammetje 100 9 amsterdamn 100 9 91 amsterdamo 100 9 amsterdamp 100 9 92 amsterdamq 100 9 amsterdamr 100 9 93 amsterdams 100 9 amsterdamsestraat 100 9 94 amsterdamt 100 9 amsterdamu 100 9 95 amsterdamv 100 9 amsterdamw 100 9 96 amsterdamweg 100 9 amsterdamx 100 9 97 amsterdamy 100 9 amsterdamz 100 9 98} 99 100do_execsql_test 1.7 { 101 SELECT word, distance, matchlen FROM demo 102 WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20 103 ORDER BY distance, word; 104} { 105 amsterdam 100 9 amsterdama 100 9 106 amsterdamania 100 9 amsterdamb 100 9 107 amsterdamc 100 9 amsterdame 100 9 108 amsterdamf 100 9 amsterdamg 100 9 109 amsterdamh 100 9 amsterdami 100 9 110 amsterdamm 100 9 amsterdammetje 100 9 111 amsterdamn 100 9 amsterdamo 100 9 112 amsterdamp 100 9 amsterdamu 100 9 113 amsterdamv 100 9 amsterdamw 100 9 114 amsterdamweg 100 9 amsterdamy 100 9 115} 116 117 118finish_test 119