2014-06-23 15:33:22 +04:00
|
|
|
# 2014 June 17
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#*************************************************************************
|
|
|
|
#
|
2015-05-01 23:38:57 +03:00
|
|
|
# Test the fts5 expression parser directly using the fts5_expr() SQL
|
|
|
|
# test function.
|
|
|
|
#
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2015-01-06 22:08:26 +03:00
|
|
|
source [file join [file dirname [info script]] fts5_common.tcl]
|
2014-06-23 15:33:22 +04:00
|
|
|
set testprefix fts5ea
|
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
|
|
|
ifcapable !fts5 {
|
2014-06-23 15:33:22 +04:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_syntax_error_test {tn expr err} {
|
|
|
|
set ::se_expr $expr
|
|
|
|
do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_syntax_test {tn expr res} {
|
|
|
|
set ::se_expr $expr
|
|
|
|
do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach {tn expr res} {
|
|
|
|
1 {abc} {"abc"}
|
|
|
|
2 {abc def} {"abc" AND "def"}
|
|
|
|
3 {abc*} {"abc" *}
|
|
|
|
4 {"abc def ghi" *} {"abc" + "def" + "ghi" *}
|
|
|
|
5 {one AND two} {"one" AND "two"}
|
|
|
|
6 {one+two} {"one" + "two"}
|
|
|
|
7 {one AND two OR three} {("one" AND "two") OR "three"}
|
|
|
|
8 {one OR two AND three} {"one" OR ("two" AND "three")}
|
|
|
|
9 {NEAR(one two)} {NEAR("one" "two", 10)}
|
|
|
|
10 {NEAR("one three"* two, 5)} {NEAR("one" + "three" * "two", 5)}
|
2015-05-01 23:38:57 +03:00
|
|
|
11 {a OR b NOT c} {"a" OR ("b" NOT "c")}
|
|
|
|
12 "\x20one\x20two\x20three" {("one" AND "two") AND "three"}
|
|
|
|
13 "\x09one\x0Atwo\x0Dthree" {("one" AND "two") AND "three"}
|
|
|
|
14 {"abc""def"} {"abc" + "def"}
|
2014-06-23 15:33:22 +04:00
|
|
|
} {
|
|
|
|
do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach {tn expr res} {
|
|
|
|
1 {c1:abc}
|
|
|
|
{c1 : "abc"}
|
|
|
|
2 {c2 : NEAR(one two) c1:"hello world"}
|
|
|
|
{c2 : NEAR("one" "two", 10) AND c1 : "hello" + "world"}
|
|
|
|
} {
|
|
|
|
do_execsql_test 2.$tn {SELECT fts5_expr($expr, 'c1', 'c2')} [list $res]
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach {tn expr err} {
|
2014-06-26 00:28:38 +04:00
|
|
|
1 {AND} {fts5: syntax error near "AND"}
|
|
|
|
2 {abc def AND} {fts5: syntax error near ""}
|
|
|
|
3 {abc OR AND} {fts5: syntax error near "AND"}
|
|
|
|
4 {(a OR b) abc} {fts5: syntax error near "abc"}
|
|
|
|
5 {NEaR (a b)} {fts5: syntax error near "NEaR"}
|
2015-05-02 23:35:24 +03:00
|
|
|
6 {NEa (a b)} {fts5: syntax error near "NEa"}
|
|
|
|
7 {(a OR b) NOT c)} {fts5: syntax error near ")"}
|
|
|
|
8 {nosuch: a nosuch2: b} {no such column: nosuch}
|
|
|
|
9 {addr: a nosuch2: b} {no such column: nosuch2}
|
|
|
|
10 {NOT} {fts5: syntax error near "NOT"}
|
|
|
|
11 {a AND "abc} {unterminated string}
|
|
|
|
|
|
|
|
12 {NEAR(a b, xyz)} {expected integer, got "xyz"}
|
2015-05-18 20:50:17 +03:00
|
|
|
13 {NEAR(a b, // )} {fts5: syntax error near "/"}
|
2015-05-18 21:03:06 +03:00
|
|
|
14 {NEAR(a b, "xyz" )} {expected integer, got ""xyz""}
|
2014-06-23 15:33:22 +04:00
|
|
|
} {
|
|
|
|
do_catchsql_test 3.$tn {SELECT fts5_expr($expr, 'name', 'addr')} [list 1 $err]
|
|
|
|
}
|
|
|
|
|
2015-05-07 22:29:46 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# Experiment with a tokenizer that considers " to be a token character.
|
|
|
|
#
|
|
|
|
do_execsql_test 4.0 {
|
|
|
|
SELECT fts5_expr('a AND """"', 'x', 'tokenize="unicode61 tokenchars ''""''"');
|
|
|
|
} {{"a" AND """"}}
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finish_test
|