xref: /sqlite-3.40.0/test/spellfix2.test (revision 4dfe98a8)
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} {
34   amsterdam      100 9
35   amsterdammetje 100 9
36   amsterdamania  100 9
37}
38
39do_execsql_test 1.2 {
40  SELECT word, distance, matchlen FROM demo WHERE
41  word MATCH 'amstedam*' AND top=3 AND distance <= 100;
42} {
43   amsterdam      100 9
44   amsterdammetje 100 9
45   amsterdamania  100 9
46}
47
48do_execsql_test 1.3 {
49  SELECT word, distance, matchlen FROM demo WHERE
50  word MATCH 'amstedam*' AND distance <= 100;
51} {
52   amsterdam         100 9
53   amsterdammetje    100 9
54   amsterdamania     100 9
55   amsterdamweg      100 9
56   amsterdamsestraat 100 9
57   amsterdamlaan     100 9
58}
59
60do_test 1.4 {
61  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} {
62    execsql { INSERT INTO demo(word) VALUES ('amsterdam' || $l) }
63  }
64} {}
65
66do_execsql_test 1.5 {
67  SELECT count(*) FROM demo WHERE word MATCH 'amstedam*' AND distance <= 100;
68  SELECT count(*) FROM demo
69  WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20;
70} {
71  32 20
72}
73
74do_execsql_test 1.6 {
75  SELECT word, distance, matchlen FROM demo
76  WHERE word MATCH 'amstedam*' AND distance <= 100;
77} {
78  amsterdam         100 9        amsterdamh        100 9
79  amsterdamm        100 9        amsterdamn        100 9
80  amsterdama        100 9        amsterdame        100 9
81  amsterdami        100 9        amsterdamo        100 9
82  amsterdamu        100 9        amsterdamy        100 9
83  amsterdammetje    100 9        amsterdamania     100 9
84  amsterdamb        100 9        amsterdamf        100 9
85  amsterdamp        100 9        amsterdamv        100 9
86  amsterdamw        100 9        amsterdamweg      100 9
87  amsterdamc        100 9        amsterdamg        100 9
88  amsterdamj        100 9        amsterdamk        100 9
89  amsterdamq        100 9        amsterdams        100 9
90  amsterdamx        100 9        amsterdamz        100 9
91  amsterdamsestraat 100 9        amsterdamd        100 9
92  amsterdamt        100 9        amsterdaml        100 9
93  amsterdamlaan     100 9        amsterdamr        100 9
94}
95
96do_execsql_test 1.7 {
97  SELECT word, distance, matchlen FROM demo
98  WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20;
99} {
100  amsterdam         100 9        amsterdamh        100 9
101  amsterdamm        100 9        amsterdamn        100 9
102  amsterdama        100 9        amsterdame        100 9
103  amsterdami        100 9        amsterdamo        100 9
104  amsterdamu        100 9        amsterdamy        100 9
105  amsterdammetje    100 9        amsterdamania     100 9
106  amsterdamb        100 9        amsterdamf        100 9
107  amsterdamp        100 9        amsterdamv        100 9
108  amsterdamw        100 9        amsterdamweg      100 9
109  amsterdamc        100 9        amsterdamg        100 9
110}
111
112
113finish_test
114
115