xref: /sqlite-3.40.0/test/fts3expr.test (revision 6bfd973c)
133e89035Sdanielk1977# 2006 September 9
233e89035Sdanielk1977#
333e89035Sdanielk1977# The author disclaims copyright to this source code.  In place of
433e89035Sdanielk1977# a legal notice, here is a blessing:
533e89035Sdanielk1977#
633e89035Sdanielk1977#    May you do good and not evil.
733e89035Sdanielk1977#    May you find forgiveness for yourself and forgive others.
833e89035Sdanielk1977#    May you share freely, never taking more than you give.
933e89035Sdanielk1977#
1033e89035Sdanielk1977#*************************************************************************
1133e89035Sdanielk1977# This file implements regression tests for SQLite library.  The
1233e89035Sdanielk1977# focus of this script is testing the FTS3 module.
1333e89035Sdanielk1977#
14ee0484c1Sdanielk1977# $Id: fts3expr.test,v 1.9 2009/07/28 16:44:26 danielk1977 Exp $
1533e89035Sdanielk1977#
1633e89035Sdanielk1977
1733e89035Sdanielk1977set testdir [file dirname $argv0]
1833e89035Sdanielk1977source $testdir/tester.tcl
1933e89035Sdanielk1977
2033e89035Sdanielk1977# If SQLITE_ENABLE_FTS3 is defined, omit this file.
2133e89035Sdanielk1977ifcapable !fts3 {
2233e89035Sdanielk1977  finish_test
2333e89035Sdanielk1977  return
2433e89035Sdanielk1977}
2533e89035Sdanielk1977
2633e89035Sdanielk1977set sqlite_fts3_enable_parentheses 1
2733e89035Sdanielk1977
2833e89035Sdanielk1977proc test_fts3expr {expr} {
2933e89035Sdanielk1977  db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')}
3033e89035Sdanielk1977}
31d6dd5defSdan
3233e89035Sdanielk1977do_test fts3expr-1.0 {
3333e89035Sdanielk1977  test_fts3expr "abcd"
3433e89035Sdanielk1977} {PHRASE 3 0 abcd}
3533e89035Sdanielk1977do_test fts3expr-1.1 {
3633e89035Sdanielk1977  test_fts3expr " tag "
3733e89035Sdanielk1977} {PHRASE 3 0 tag}
3833e89035Sdanielk1977
3933e89035Sdanielk1977do_test fts3expr-1.2 {
4033e89035Sdanielk1977  test_fts3expr "ab AND cd"
4133e89035Sdanielk1977} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
42b39187aeSdrhdo_test fts3expr-1.2.1 {
43b39187aeSdrh  test_fts3expr "ab cd"
44b39187aeSdrh} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
4533e89035Sdanielk1977do_test fts3expr-1.3 {
4633e89035Sdanielk1977  test_fts3expr "ab OR cd"
4733e89035Sdanielk1977} {OR {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
4833e89035Sdanielk1977do_test fts3expr-1.4 {
4933e89035Sdanielk1977  test_fts3expr "ab NOT cd"
5033e89035Sdanielk1977} {NOT {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
5133e89035Sdanielk1977do_test fts3expr-1.5 {
5233e89035Sdanielk1977  test_fts3expr "ab NEAR cd"
5333e89035Sdanielk1977} {NEAR/10 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
54b39187aeSdrhdo_test fts3expr-1.6.1 {
5533e89035Sdanielk1977  test_fts3expr "ab NEAR/5 cd"
5633e89035Sdanielk1977} {NEAR/5 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
57b39187aeSdrhdo_test fts3expr-1.6.2 {
58b39187aeSdrh  test_fts3expr "ab NEAR/87654321 cd"
59b39187aeSdrh} {NEAR/87654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
60b39187aeSdrhdo_test fts3expr-1.6.3 {
61b39187aeSdrh  test_fts3expr "ab NEAR/7654321 cd"
62b39187aeSdrh} {NEAR/7654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
63b39187aeSdrhdo_test fts3expr-1.6.4 {
64b39187aeSdrh  test_fts3expr "ab NEAR/654321 cd"
65b39187aeSdrh} {NEAR/654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
66b39187aeSdrhdo_test fts3expr-1.6.5 {
67b39187aeSdrh  test_fts3expr "ab NEAR/54321 cd"
68b39187aeSdrh} {NEAR/54321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
69b39187aeSdrhdo_test fts3expr-1.6.6 {
70b39187aeSdrh  test_fts3expr "ab NEAR/4321 cd"
71b39187aeSdrh} {NEAR/4321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
72b39187aeSdrhdo_test fts3expr-1.6.7 {
73b39187aeSdrh  test_fts3expr "ab NEAR/321 cd"
74b39187aeSdrh} {NEAR/321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
75b39187aeSdrhdo_test fts3expr-1.6.8 {
76b39187aeSdrh  test_fts3expr "ab NEAR/21 cd"
77b39187aeSdrh} {NEAR/21 {PHRASE 3 0 ab} {PHRASE 3 0 cd}}
7833e89035Sdanielk1977
7933e89035Sdanielk1977do_test fts3expr-1.7 {
8033e89035Sdanielk1977  test_fts3expr {"one two three"}
8133e89035Sdanielk1977} {PHRASE 3 0 one two three}
82b39187aeSdrhdo_test fts3expr-1.8.1 {
8333e89035Sdanielk1977  test_fts3expr {zero "one two three" four}
8433e89035Sdanielk1977} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}}
85b39187aeSdrhdo_test fts3expr-1.8.2 {
86b39187aeSdrh  test_fts3expr {zero AND "one two three" four}
87b39187aeSdrh} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}}
88b39187aeSdrhdo_test fts3expr-1.8.3 {
89b39187aeSdrh  test_fts3expr {zero "one two three" AND four}
90b39187aeSdrh} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}}
91b39187aeSdrhdo_test fts3expr-1.8.4 {
92b39187aeSdrh  test_fts3expr {zero AND "one two three" AND four}
93b39187aeSdrh} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}}
94b39187aeSdrhdo_test fts3expr-1.9.1 {
95b39187aeSdrh  test_fts3expr {"one* two three"}
96b39187aeSdrh} {PHRASE 3 0 one+ two three}
97b39187aeSdrhdo_test fts3expr-1.9.2 {
98b39187aeSdrh  test_fts3expr {"one two* three"}
99b39187aeSdrh} {PHRASE 3 0 one two+ three}
100b39187aeSdrhdo_test fts3expr-1.9.3 {
101b39187aeSdrh  test_fts3expr {"one* two* three"}
102b39187aeSdrh} {PHRASE 3 0 one+ two+ three}
103b39187aeSdrhdo_test fts3expr-1.9.4 {
104b39187aeSdrh  test_fts3expr {"one two three*"}
105b39187aeSdrh} {PHRASE 3 0 one two three+}
106b39187aeSdrhdo_test fts3expr-1.9.5 {
10733e89035Sdanielk1977  test_fts3expr {"one* two three*"}
10833e89035Sdanielk1977} {PHRASE 3 0 one+ two three+}
109b39187aeSdrhdo_test fts3expr-1.9.6 {
110b39187aeSdrh  test_fts3expr {"one two* three*"}
111b39187aeSdrh} {PHRASE 3 0 one two+ three+}
112b39187aeSdrhdo_test fts3expr-1.9.7 {
113b39187aeSdrh  test_fts3expr {"one* two* three*"}
114b39187aeSdrh} {PHRASE 3 0 one+ two+ three+}
11533e89035Sdanielk1977
11633e89035Sdanielk1977do_test fts3expr-1.10 {
11733e89035Sdanielk1977  test_fts3expr {one* two}
11833e89035Sdanielk1977} {AND {PHRASE 3 0 one+} {PHRASE 3 0 two}}
11933e89035Sdanielk1977do_test fts3expr-1.11 {
12033e89035Sdanielk1977  test_fts3expr {one two*}
12133e89035Sdanielk1977} {AND {PHRASE 3 0 one} {PHRASE 3 0 two+}}
12233e89035Sdanielk1977
12333e89035Sdanielk1977do_test fts3expr-1.14 {
12433e89035Sdanielk1977  test_fts3expr {a:one two}
12533e89035Sdanielk1977} {AND {PHRASE 0 0 one} {PHRASE 3 0 two}}
126ee0484c1Sdanielk1977do_test fts3expr-1.15.1 {
12733e89035Sdanielk1977  test_fts3expr {one b:two}
12833e89035Sdanielk1977} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}}
129ee0484c1Sdanielk1977do_test fts3expr-1.15.2 {
130ee0484c1Sdanielk1977  test_fts3expr {one B:two}
131ee0484c1Sdanielk1977} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}}
13233e89035Sdanielk1977
133b39187aeSdrhdo_test fts3expr-1.16 {
134b39187aeSdrh  test_fts3expr {one AND two AND three AND four AND five}
135b39187aeSdrh} [list AND \
136b39187aeSdrh        [list AND \
137b39187aeSdrh              [list AND \
138b39187aeSdrh                    [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \
139b39187aeSdrh                    {PHRASE 3 0 three} \
140b39187aeSdrh              ] \
141b39187aeSdrh              {PHRASE 3 0 four} \
142b39187aeSdrh        ] \
143b39187aeSdrh        {PHRASE 3 0 five} \
144b39187aeSdrh  ]
145b39187aeSdrhdo_test fts3expr-1.17 {
146b39187aeSdrh  test_fts3expr {(one AND two) AND ((three AND four) AND five)}
147b39187aeSdrh} [list AND \
148b39187aeSdrh        [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \
149b39187aeSdrh        [list AND \
150b39187aeSdrh              [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \
151b39187aeSdrh             {PHRASE 3 0 five} \
152b39187aeSdrh        ] \
153b39187aeSdrh  ]
154b39187aeSdrhdo_test fts3expr-1.18 {
155b39187aeSdrh  test_fts3expr {(one AND two) OR ((three AND four) AND five)}
156b39187aeSdrh} [list OR \
157b39187aeSdrh        [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \
158b39187aeSdrh        [list AND \
159b39187aeSdrh              [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \
160b39187aeSdrh             {PHRASE 3 0 five} \
161b39187aeSdrh        ] \
162b39187aeSdrh  ]
163b39187aeSdrhdo_test fts3expr-1.19 {
164b39187aeSdrh  test_fts3expr {(one AND two) AND ((three AND four) OR five)}
165b39187aeSdrh} [list AND \
166b39187aeSdrh        [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \
167b39187aeSdrh        [list OR \
168b39187aeSdrh              [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \
169b39187aeSdrh             {PHRASE 3 0 five} \
170b39187aeSdrh        ] \
171b39187aeSdrh  ]
172b39187aeSdrhdo_test fts3expr-1.20 {
173b39187aeSdrh  test_fts3expr {(one OR two) AND ((three OR four) AND five)}
174b39187aeSdrh} [list AND \
175b39187aeSdrh        [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \
176b39187aeSdrh        [list AND \
177b39187aeSdrh              [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \
178b39187aeSdrh             {PHRASE 3 0 five} \
179b39187aeSdrh        ] \
180b39187aeSdrh  ]
181b39187aeSdrhdo_test fts3expr-1.21 {
182b39187aeSdrh  test_fts3expr {(one OR two) AND ((three NOT four) AND five)}
183b39187aeSdrh} [list AND \
184b39187aeSdrh        [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \
185b39187aeSdrh        [list AND \
186b39187aeSdrh              [list NOT {PHRASE 3 0 three} {PHRASE 3 0 four}] \
187b39187aeSdrh             {PHRASE 3 0 five} \
188b39187aeSdrh        ] \
189b39187aeSdrh  ]
190b39187aeSdrhdo_test fts3expr-1.22 {
191b39187aeSdrh  test_fts3expr {(one OR two) NOT ((three OR four) AND five)}
192b39187aeSdrh} [list NOT \
193b39187aeSdrh        [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \
194b39187aeSdrh        [list AND \
195b39187aeSdrh              [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \
196b39187aeSdrh             {PHRASE 3 0 five} \
197b39187aeSdrh        ] \
198b39187aeSdrh  ]
199b39187aeSdrhdo_test fts3expr-1.23 {
200b39187aeSdrh  test_fts3expr {(((((one OR two))))) NOT (((((three OR four))) AND five))}
201b39187aeSdrh} [list NOT \
202b39187aeSdrh        [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \
203b39187aeSdrh        [list AND \
204b39187aeSdrh              [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \
205b39187aeSdrh             {PHRASE 3 0 five} \
206b39187aeSdrh        ] \
207b39187aeSdrh  ]
208b39187aeSdrhdo_test fts3expr-1.24 {
209b39187aeSdrh  test_fts3expr {one NEAR two}
210b39187aeSdrh} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}]
211b39187aeSdrhdo_test fts3expr-1.25 {
212b39187aeSdrh  test_fts3expr {(one NEAR two)}
213b39187aeSdrh} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}]
214b39187aeSdrhdo_test fts3expr-1.26 {
215b39187aeSdrh  test_fts3expr {((((((one NEAR two))))))}
216b39187aeSdrh} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}]
217b39187aeSdrhdo_test fts3expr-1.27 {
218b39187aeSdrh  test_fts3expr {(one NEAR two) OR ((three OR four) AND five)}
219b39187aeSdrh} [list OR \
220b39187aeSdrh        [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] \
221b39187aeSdrh        [list AND \
222b39187aeSdrh              [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \
223b39187aeSdrh             {PHRASE 3 0 five} \
224b39187aeSdrh        ] \
225b39187aeSdrh  ]
226b39187aeSdrhdo_test fts3expr-1.28 {
227b39187aeSdrh  test_fts3expr {(one NEAR/321 two) OR ((three OR four) AND five)}
228b39187aeSdrh} [list OR \
229b39187aeSdrh        [list NEAR/321 {PHRASE 3 0 one} {PHRASE 3 0 two}] \
230b39187aeSdrh        [list AND \
231b39187aeSdrh              [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \
232b39187aeSdrh             {PHRASE 3 0 five} \
233b39187aeSdrh        ] \
234b39187aeSdrh  ]
235b39187aeSdrh
23633e89035Sdanielk1977proc strip_phrase_data {L} {
23733e89035Sdanielk1977  if {[lindex $L 0] eq "PHRASE"} {
23833e89035Sdanielk1977    return [lrange $L 3 end]
23933e89035Sdanielk1977  }
24033e89035Sdanielk1977  return [list \
24133e89035Sdanielk1977    [lindex $L 0] \
24233e89035Sdanielk1977    [strip_phrase_data [lindex $L 1]] \
24333e89035Sdanielk1977    [strip_phrase_data [lindex $L 2]] \
24433e89035Sdanielk1977  ]
24533e89035Sdanielk1977}
24633e89035Sdanielk1977proc test_fts3expr2 {expr} {
24733e89035Sdanielk1977  strip_phrase_data [
24833e89035Sdanielk1977    db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')}
24933e89035Sdanielk1977  ]
25033e89035Sdanielk1977}
25133e89035Sdanielk1977do_test fts3expr-2.1 {
25233e89035Sdanielk1977  test_fts3expr2 "ab OR cd AND ef"
25333e89035Sdanielk1977} {OR ab {AND cd ef}}
25433e89035Sdanielk1977do_test fts3expr-2.2 {
25533e89035Sdanielk1977  test_fts3expr2 "cd AND ef OR ab"
25633e89035Sdanielk1977} {OR {AND cd ef} ab}
25733e89035Sdanielk1977do_test fts3expr-2.3 {
25833e89035Sdanielk1977  test_fts3expr2 "ab AND cd AND ef OR gh"
25933e89035Sdanielk1977} {OR {AND {AND ab cd} ef} gh}
26033e89035Sdanielk1977do_test fts3expr-2.4 {
26133e89035Sdanielk1977  test_fts3expr2 "ab AND cd OR ef AND gh"
26233e89035Sdanielk1977} {OR {AND ab cd} {AND ef gh}}
26333e89035Sdanielk1977do_test fts3expr-2.5 {
26433e89035Sdanielk1977  test_fts3expr2 "ab cd"
26533e89035Sdanielk1977} {AND ab cd}
26633e89035Sdanielk1977
26733e89035Sdanielk1977do_test fts3expr-3.1 {
26833e89035Sdanielk1977  test_fts3expr2 "(ab OR cd) AND ef"
26933e89035Sdanielk1977} {AND {OR ab cd} ef}
27033e89035Sdanielk1977do_test fts3expr-3.2 {
27133e89035Sdanielk1977  test_fts3expr2 "ef AND (ab OR cd)"
27233e89035Sdanielk1977} {AND ef {OR ab cd}}
27333e89035Sdanielk1977do_test fts3expr-3.3 {
27433e89035Sdanielk1977  test_fts3expr2 "(ab OR cd)"
27533e89035Sdanielk1977} {OR ab cd}
27633e89035Sdanielk1977do_test fts3expr-3.4 {
27733e89035Sdanielk1977  test_fts3expr2 "(((ab OR cd)))"
27833e89035Sdanielk1977} {OR ab cd}
27933e89035Sdanielk1977
28049b4b4d8Sdanielk1977do_test fts3expr-3.5 {
28149b4b4d8Sdanielk1977  test_fts3expr2 "one AND (two NEAR three)"
28249b4b4d8Sdanielk1977} {AND one {NEAR/10 two three}}
2835973e6a3Sdanielk1977do_test fts3expr-3.6 {
2845973e6a3Sdanielk1977  test_fts3expr2 "one (two NEAR three)"
2855973e6a3Sdanielk1977} {AND one {NEAR/10 two three}}
2865973e6a3Sdanielk1977do_test fts3expr-3.7 {
2875973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) one"
2885973e6a3Sdanielk1977} {AND {NEAR/10 two three} one}
2895973e6a3Sdanielk1977do_test fts3expr-3.8 {
2905973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) AND one"
2915973e6a3Sdanielk1977} {AND {NEAR/10 two three} one}
2925973e6a3Sdanielk1977do_test fts3expr-3.9 {
2935973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) (four five)"
2945973e6a3Sdanielk1977} {AND {NEAR/10 two three} {AND four five}}
2955973e6a3Sdanielk1977do_test fts3expr-3.10 {
2965973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) AND (four five)"
2975973e6a3Sdanielk1977} {AND {NEAR/10 two three} {AND four five}}
2985973e6a3Sdanielk1977do_test fts3expr-3.11 {
2995973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) (four NEAR five)"
3005973e6a3Sdanielk1977} {AND {NEAR/10 two three} {NEAR/10 four five}}
3015973e6a3Sdanielk1977do_test fts3expr-3.12 {
3025973e6a3Sdanielk1977  test_fts3expr2 "(two NEAR three) OR (four NEAR five)"
3035973e6a3Sdanielk1977} {OR {NEAR/10 two three} {NEAR/10 four five}}
3045973e6a3Sdanielk1977
305758bc07cSdanielk1977do_test fts3expr-3.13 {
306758bc07cSdanielk1977  test_fts3expr2 "(two NEAR/1a three)"
307758bc07cSdanielk1977} {AND {AND {AND two near} 1a} three}
308758bc07cSdanielk1977
309758bc07cSdanielk1977do_test fts3expr-3.14 {
310758bc07cSdanielk1977  test_fts3expr2 "(two NEAR// three)"
311758bc07cSdanielk1977} {AND {AND two near} three}
312758bc07cSdanielk1977do_test fts3expr-3.15 {
313758bc07cSdanielk1977  test_fts3expr2 "(two NEAR/: three)"
314758bc07cSdanielk1977} {AND {AND two near} three}
315758bc07cSdanielk1977
316758bc07cSdanielk1977do_test fts3expr-3.16 {
317758bc07cSdanielk1977  test_fts3expr2 "(two NEAR three)OR(four NEAR five)"
318758bc07cSdanielk1977} {OR {NEAR/10 two three} {NEAR/10 four five}}
319758bc07cSdanielk1977do_test fts3expr-3.17 {
320758bc07cSdanielk1977  test_fts3expr2 "(two NEAR three)OR\"four five\""
321758bc07cSdanielk1977} {OR {NEAR/10 two three} {four five}}
322758bc07cSdanielk1977do_test fts3expr-3.18 {
323758bc07cSdanielk1977  test_fts3expr2 "one \u0080wo"
324758bc07cSdanielk1977} "AND one \u0080wo"
325758bc07cSdanielk1977
326758bc07cSdanielk1977
32749b4b4d8Sdanielk1977
32833e89035Sdanielk1977#------------------------------------------------------------------------
32933e89035Sdanielk1977# The following tests, fts3expr-4.*, test the parsers response to syntax
33033e89035Sdanielk1977# errors in query expressions. This is done using a real fts3 table and
33133e89035Sdanielk1977# MATCH clauses, not the parser test interface.
33233e89035Sdanielk1977#
33333e89035Sdanielk1977do_test fts3expr-4.1 {
33433e89035Sdanielk1977  execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) }
33533e89035Sdanielk1977} {}
33633e89035Sdanielk1977
33733e89035Sdanielk1977# Mismatched parenthesis:
33833e89035Sdanielk1977do_test fts3expr-4.2.1 {
33933e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world))' }
3403a3dd3acSdrh} {1 {malformed MATCH expression: [example AND (hello OR world))]}}
34133e89035Sdanielk1977do_test fts3expr-4.2.2 {
34233e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world' }
3433a3dd3acSdrh} {1 {malformed MATCH expression: [example AND (hello OR world]}}
344fc8c9f84Sdanielk1977do_test fts3expr-4.2.3 {
345fc8c9f84Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello' }
3463a3dd3acSdrh} {1 {malformed MATCH expression: [(hello]}}
347fc8c9f84Sdanielk1977do_test fts3expr-4.2.4 {
348fc8c9f84Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH '(' }
3493a3dd3acSdrh} {1 {malformed MATCH expression: [(]}}
350fc8c9f84Sdanielk1977do_test fts3expr-4.2.5 {
351fc8c9f84Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH ')' }
3523a3dd3acSdrh} {1 {malformed MATCH expression: [)]}}
353fc8c9f84Sdanielk1977
354fc8c9f84Sdanielk1977do_test fts3expr-4.2.6 {
355fc8c9f84Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example (hello world' }
3563a3dd3acSdrh} {1 {malformed MATCH expression: [example (hello world]}}
35733e89035Sdanielk1977
35833e89035Sdanielk1977# Unterminated quotation marks:
35933e89035Sdanielk1977do_test fts3expr-4.3.1 {
36033e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR "hello world' }
3613a3dd3acSdrh} {1 {malformed MATCH expression: [example OR "hello world]}}
36233e89035Sdanielk1977do_test fts3expr-4.3.2 {
36333e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR hello world"' }
3643a3dd3acSdrh} {1 {malformed MATCH expression: [example OR hello world"]}}
36533e89035Sdanielk1977
36633e89035Sdanielk1977# Binary operators without the required operands.
36733e89035Sdanielk1977do_test fts3expr-4.4.1 {
36833e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'OR hello world' }
3693a3dd3acSdrh} {1 {malformed MATCH expression: [OR hello world]}}
37033e89035Sdanielk1977do_test fts3expr-4.4.2 {
37133e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'hello world OR' }
3723a3dd3acSdrh} {1 {malformed MATCH expression: [hello world OR]}}
37333e89035Sdanielk1977do_test fts3expr-4.4.3 {
37433e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (hello world OR) two' }
3753a3dd3acSdrh} {1 {malformed MATCH expression: [one (hello world OR) two]}}
37633e89035Sdanielk1977do_test fts3expr-4.4.4 {
37733e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (OR hello world) two' }
3783a3dd3acSdrh} {1 {malformed MATCH expression: [one (OR hello world) two]}}
37933e89035Sdanielk1977
38033e89035Sdanielk1977# NEAR operators with something other than phrases as arguments.
38133e89035Sdanielk1977do_test fts3expr-4.5.1 {
38233e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello OR world) NEAR one' }
3833a3dd3acSdrh} {1 {malformed MATCH expression: [(hello OR world) NEAR one]}}
38433e89035Sdanielk1977do_test fts3expr-4.5.2 {
38533e89035Sdanielk1977  catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one NEAR (hello OR world)' }
3863a3dd3acSdrh} {1 {malformed MATCH expression: [one NEAR (hello OR world)]}}
38733e89035Sdanielk1977
38833e89035Sdanielk1977#------------------------------------------------------------------------
38933e89035Sdanielk1977# The following OOM tests are designed to cover cases in fts3_expr.c.
39033e89035Sdanielk1977#
39133e89035Sdanielk1977source $testdir/malloc_common.tcl
39233e89035Sdanielk1977do_malloc_test fts3expr-malloc-1 -sqlbody {
39333e89035Sdanielk1977  SELECT fts3_exprtest('simple', 'a b c "d e f"', 'a', 'b', 'c')
39433e89035Sdanielk1977}
39533e89035Sdanielk1977do_malloc_test fts3expr-malloc-2 -tclprep {
39633e89035Sdanielk1977  set sqlite_fts3_enable_parentheses 0
39733e89035Sdanielk1977} -sqlbody {
39833e89035Sdanielk1977  SELECT fts3_exprtest('simple', 'a -b', 'a', 'b', 'c')
39933e89035Sdanielk1977} -cleanup {
40033e89035Sdanielk1977  set sqlite_fts3_enable_parentheses 1
40133e89035Sdanielk1977}
40233e89035Sdanielk1977
40333e89035Sdanielk1977#------------------------------------------------------------------------
40433e89035Sdanielk1977# The following tests are not very important. They cover error handling
40533e89035Sdanielk1977# cases in the test code, which makes test coverage easier to measure.
40633e89035Sdanielk1977#
40733e89035Sdanielk1977do_test fts3expr-5.1 {
40833e89035Sdanielk1977  catchsql { SELECT fts3_exprtest('simple', 'a b') }
40933e89035Sdanielk1977} {1 {Usage: fts3_exprtest(tokenizer, expr, col1, ...}}
41033e89035Sdanielk1977do_test fts3expr-5.2 {
41133e89035Sdanielk1977  catchsql { SELECT fts3_exprtest('doesnotexist', 'a b', 'c') }
412*6bfd973cSdrh} {1 {unknown tokenizer: doesnotexist}}
41333e89035Sdanielk1977do_test fts3expr-5.3 {
41433e89035Sdanielk1977  catchsql { SELECT fts3_exprtest('simple', 'a b OR', 'c') }
41533e89035Sdanielk1977} {1 {Error parsing expression}}
41633e89035Sdanielk1977
41733e89035Sdanielk1977#------------------------------------------------------------------------
41833e89035Sdanielk1977# The next set of tests verifies that things actually work as they are
41933e89035Sdanielk1977# supposed to when using the new syntax.
42033e89035Sdanielk1977#
42133e89035Sdanielk1977do_test fts3expr-6.1 {
42233e89035Sdanielk1977  execsql {
42333e89035Sdanielk1977    CREATE VIRTUAL TABLE t1 USING fts3(a);
42433e89035Sdanielk1977  }
42533e89035Sdanielk1977  for {set ii 1} {$ii < 32} {incr ii} {
42633e89035Sdanielk1977    set v [list]
42733e89035Sdanielk1977    if {$ii & 1}  { lappend v one }
42833e89035Sdanielk1977    if {$ii & 2}  { lappend v two }
42933e89035Sdanielk1977    if {$ii & 4}  { lappend v three }
43033e89035Sdanielk1977    if {$ii & 8}  { lappend v four }
43133e89035Sdanielk1977    if {$ii & 16} { lappend v five }
43233e89035Sdanielk1977    execsql { INSERT INTO t1 VALUES($v) }
43333e89035Sdanielk1977  }
43433e89035Sdanielk1977
43533e89035Sdanielk1977  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'five four one' ORDER BY rowid}
43633e89035Sdanielk1977} {25 27 29 31}
43733e89035Sdanielk1977
43833e89035Sdanielk1977foreach {id expr res} {
43933e89035Sdanielk1977
44033e89035Sdanielk1977  2 "five four NOT one" {24 26 28 30}
44133e89035Sdanielk1977
44233e89035Sdanielk1977  3 "five AND four OR one"
44333e89035Sdanielk1977      {1 3 5 7 9 11 13 15 17 19 21 23 24 25 26 27 28 29 30 31}
44433e89035Sdanielk1977
44533e89035Sdanielk1977  4 "five AND (four OR one)" {17 19 21 23 24 25 26 27 28 29 30 31}
44633e89035Sdanielk1977
44733e89035Sdanielk1977  5 "five NOT (four OR one)" {16 18 20 22}
44833e89035Sdanielk1977
44933e89035Sdanielk1977  6 "(five NOT (four OR one)) OR (five AND (four OR one))"
45033e89035Sdanielk1977      {16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
45133e89035Sdanielk1977
45233e89035Sdanielk1977  7 "(five OR one) AND two AND three" {7 15 22 23 30 31}
45333e89035Sdanielk1977
45433e89035Sdanielk1977  8 "five OR one AND two AND three"
45533e89035Sdanielk1977    {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
45633e89035Sdanielk1977
45733e89035Sdanielk1977  9 "five OR one two three"
45833e89035Sdanielk1977    {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
45933e89035Sdanielk1977
46033e89035Sdanielk1977  10 "five OR \"one two three\""
46133e89035Sdanielk1977    {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
46233e89035Sdanielk1977
46333e89035Sdanielk1977  11 "one two OR four five NOT three" {3 7 11 15 19 23 24 25 26 27 31}
46433e89035Sdanielk1977
46533e89035Sdanielk1977  12 "(one two OR four five) NOT three" {3 11 19 24 25 26 27}
46633e89035Sdanielk1977
46733e89035Sdanielk1977  13 "((((((one two OR four five)))))) NOT three" {3 11 19 24 25 26 27}
46833e89035Sdanielk1977
46933e89035Sdanielk1977} {
470e932ba26Sdanielk1977  do_test fts3expr-6.1.$id {
47133e89035Sdanielk1977    execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid }
47233e89035Sdanielk1977  } $res
47333e89035Sdanielk1977}
47433e89035Sdanielk1977
475e932ba26Sdanielk1977set sqlite_fts3_enable_parentheses 0
476e932ba26Sdanielk1977foreach {id expr res} {
477e932ba26Sdanielk1977  1 "one -two three"  {5 13 21 29}
478e932ba26Sdanielk1977  2 "-two one three"  {5 13 21 29}
479e932ba26Sdanielk1977  3 "one three -two"  {5 13 21 29}
480e932ba26Sdanielk1977  4 "-one -two three" {4 12 20 28}
481e932ba26Sdanielk1977  5 "three -one -two" {4 12 20 28}
482e932ba26Sdanielk1977  6 "-one three -two" {4 12 20 28}
483e932ba26Sdanielk1977} {
484e932ba26Sdanielk1977  do_test fts3expr-6.2.$id {
485e932ba26Sdanielk1977    execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid }
486e932ba26Sdanielk1977  } $res
487e932ba26Sdanielk1977}
488e932ba26Sdanielk1977set sqlite_fts3_enable_parentheses 1
489e932ba26Sdanielk1977
4902fe5cb18Sdanielk1977do_test fts3expr-7.1 {
4912fe5cb18Sdanielk1977  execsql {
4922fe5cb18Sdanielk1977    CREATE VIRTUAL TABLE test USING fts3 (keyword);
4932fe5cb18Sdanielk1977    INSERT INTO test VALUES ('abc');
4942fe5cb18Sdanielk1977    SELECT * FROM test WHERE keyword MATCH '""';
4952fe5cb18Sdanielk1977  }
4962fe5cb18Sdanielk1977} {}
4972fe5cb18Sdanielk1977
498e932ba26Sdanielk1977
499d6dd5defSdando_test fts3expr-8.0 { test_fts3expr "(blah)" } {PHRASE 3 0 blah}
500d6dd5defSdando_test fts3expr-8.1 { test_fts3expr "(blah.)" } {PHRASE 3 0 blah}
501d6dd5defSdando_test fts3expr-8.2 { test_fts3expr "(blah,)" } {PHRASE 3 0 blah}
502d6dd5defSdando_test fts3expr-8.3 { test_fts3expr "(blah!)" } {PHRASE 3 0 blah}
503d6dd5defSdando_test fts3expr-8.4 { test_fts3expr "(blah-)" } {PHRASE 3 0 blah}
504d6dd5defSdan
505d6dd5defSdando_test fts3expr-8.5 { test_fts3expr "((blah.))" } {PHRASE 3 0 blah}
506d6dd5defSdando_test fts3expr-8.6 { test_fts3expr "(((blah,)))" } {PHRASE 3 0 blah}
507d6dd5defSdando_test fts3expr-8.7 { test_fts3expr "((((blah!))))" } {PHRASE 3 0 blah}
508d6dd5defSdan
509d6dd5defSdando_test fts3expr-8.8 { test_fts3expr "(,(blah-),)" } {PHRASE 3 0 blah}
510d6dd5defSdan
51133e89035Sdanielk1977set sqlite_fts3_enable_parentheses 0
512d2d8ca60Sdan
513d2d8ca60Sdando_test fts3expr-9.1 {
514d2d8ca60Sdan  test_fts3expr "f (e NEAR/2 a)"
515d2d8ca60Sdan} {AND {PHRASE 3 0 f} {NEAR/2 {PHRASE 3 0 e} {PHRASE 3 0 a}}}
516d2d8ca60Sdan
51721690ff7Sdando_test fts3expr-10.1 { test_fts3expr "abc *" } {PHRASE 3 0 abc}
51821690ff7Sdando_test fts3expr-10.2 { test_fts3expr "*" } {}
51921690ff7Sdando_test fts3expr-10.3 { test_fts3expr "abc*" } {PHRASE 3 0 abc+}
52021690ff7Sdan
52133e89035Sdanielk1977finish_test
522