3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
12 # Test the fts5 expression parser directly using the fts5_expr() SQL
16 source [file join [file dirname [info script]] fts5_common.tcl]
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 proc do_syntax_error_test {tn expr err} {
27 do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
30 proc do_syntax_test {tn expr res} {
32 do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
35 foreach {tn expr res} {
37 2 {abc def} {"abc" AND "def"}
39 4 {"abc def ghi" *} {"abc" + "def" + "ghi" *}
40 5 {one AND two} {"one" AND "two"}
41 6 {one+two} {"one" + "two"}
42 7 {one AND two OR three} {("one" AND "two") OR "three"}
43 8 {one OR two AND three} {"one" OR ("two" AND "three")}
44 9 {NEAR(one two)} {NEAR("one" "two", 10)}
45 10 {NEAR("one three"* two, 5)} {NEAR("one" + "three" * "two", 5)}
46 11 {a OR b NOT c} {"a" OR ("b" NOT "c")}
47 12 "\x20one\x20two\x20three" {"one" AND "two" AND "three"}
48 13 "\x09one\x0Atwo\x0Dthree" {"one" AND "two" AND "three"}
49 14 {"abc""def"} {"abc" + "def"}
51 do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
54 foreach {tn expr res} {
57 2 {c2 : NEAR(one two) c1:"hello world"}
58 {c2 : NEAR("one" "two", 10) AND c1 : "hello" + "world"}
60 do_execsql_test 2.$tn {SELECT fts5_expr($expr, 'c1', 'c2')} [list $res]
63 foreach {tn expr err} {
64 1 {AND} {fts5: syntax error near "AND"}
65 2 {abc def AND} {fts5: syntax error near ""}
66 3 {abc OR AND} {fts5: syntax error near "AND"}
67 4 {(a OR b) abc} {fts5: syntax error near "abc"}
68 5 {NEaR (a b)} {fts5: syntax error near "NEaR"}
69 6 {NEa (a b)} {fts5: syntax error near "NEa"}
70 7 {(a OR b) NOT c)} {fts5: syntax error near ")"}
71 8 {nosuch: a nosuch2: b} {no such column: nosuch}
72 9 {addr: a nosuch2: b} {no such column: nosuch2}
73 10 {NOT} {fts5: syntax error near "NOT"}
74 11 {a AND "abc} {unterminated string}
76 12 {NEAR(a b, xyz)} {expected integer, got "xyz"}
77 13 {NEAR(a b, // )} {fts5: syntax error near "/"}
78 14 {NEAR(a b, "xyz" )} {expected integer, got ""xyz""}
80 do_catchsql_test 3.$tn {SELECT fts5_expr($expr, 'name', 'addr')} [list 1 $err]
83 #-------------------------------------------------------------------------
84 # Experiment with a tokenizer that considers " to be a token character.
87 SELECT fts5_expr('a AND """"', 'x', 'tokenize="unicode61 tokenchars ''""''"');
90 #-------------------------------------------------------------------------
91 # Experiment with a tokenizer that considers " to be a token character.
93 do_catchsql_test 5.0 {
94 SELECT fts5_expr('abc | def');
95 } {1 {fts5: syntax error near "|"}}