blob: d1a13284ea63dd0c75ff83037718c49edacd10ce [file] [log] [blame]
danc1e63be2015-08-18 19:09:28 +00001# 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
drhe5c61f82015-09-18 15:38:07 +000032 WHERE word MATCH 'amstedam*' AND top=3
33 ORDER BY +word;
danc1e63be2015-08-18 19:09:28 +000034} {
35 amsterdam 100 9
danc1e63be2015-08-18 19:09:28 +000036 amsterdamania 100 9
drhe5c61f82015-09-18 15:38:07 +000037 amsterdammetje 100 9
danc1e63be2015-08-18 19:09:28 +000038}
39
40do_execsql_test 1.2 {
41 SELECT word, distance, matchlen FROM demo WHERE
drhe5c61f82015-09-18 15:38:07 +000042 word MATCH 'amstedam*' AND top=3 AND distance <= 100
43 ORDER BY +word;
danc1e63be2015-08-18 19:09:28 +000044} {
45 amsterdam 100 9
danc1e63be2015-08-18 19:09:28 +000046 amsterdamania 100 9
drhe5c61f82015-09-18 15:38:07 +000047 amsterdammetje 100 9
danc1e63be2015-08-18 19:09:28 +000048}
49
50do_execsql_test 1.3 {
51 SELECT word, distance, matchlen FROM demo WHERE
drhe5c61f82015-09-18 15:38:07 +000052 word MATCH 'amstedam*' AND distance <= 100
53 ORDER BY +word;
danc1e63be2015-08-18 19:09:28 +000054} {
55 amsterdam 100 9
danc1e63be2015-08-18 19:09:28 +000056 amsterdamania 100 9
danc1e63be2015-08-18 19:09:28 +000057 amsterdamlaan 100 9
drhe5c61f82015-09-18 15:38:07 +000058 amsterdammetje 100 9
59 amsterdamsestraat 100 9
60 amsterdamweg 100 9
danc1e63be2015-08-18 19:09:28 +000061}
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
drh1dcc97c2015-10-07 16:14:18 +000079 WHERE word MATCH 'amstedam*' AND distance <= 100
80 ORDER BY distance, word;
danc1e63be2015-08-18 19:09:28 +000081} {
drh1dcc97c2015-10-07 16:14:18 +000082 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
danc1e63be2015-08-18 19:09:28 +000098}
99
100do_execsql_test 1.7 {
101 SELECT word, distance, matchlen FROM demo
drh1dcc97c2015-10-07 16:14:18 +0000102 WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20
103 ORDER BY distance, word;
danc1e63be2015-08-18 19:09:28 +0000104} {
drh1dcc97c2015-10-07 16:14:18 +0000105 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
danc1e63be2015-08-18 19:09:28 +0000115}
116
117
118finish_test