interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / test / fts5ea.test

99 lines · 3635 bytes Raw Blame History
1# 2014 June 17
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# Test the fts5 expression parser directly using the fts5_expr() SQL
13# test function.
14#
15
16source [file join [file dirname [info script]] fts5_common.tcl]
17set testprefix fts5ea
18
19# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
20ifcapable !fts5 {
21 finish_test
22 return
23}
24
25proc do_syntax_error_test {tn expr err} {
26 set ::se_expr $expr
27 do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
28}
29
30proc do_syntax_test {tn expr res} {
31 set ::se_expr $expr
32 do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
33}
34
35foreach {tn expr res} {
36 1 {abc} {"abc"}
37 2 {abc def} {"abc" AND "def"}
38 3 {abc*} {"abc" *}
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"}
50} {
51 do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
52}
53
54foreach {tn expr res} {
55 1 {c1:abc}
56 {c1 : "abc"}
57 2 {c2 : NEAR(one two) c1:"hello world"}
58 {c2 : NEAR("one" "two", 10) AND c1 : "hello" + "world"}
59} {
60 do_execsql_test 2.$tn {SELECT fts5_expr($expr, 'c1', 'c2')} [list $res]
61}
62
63foreach {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}
75
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""}
79} {
80 do_catchsql_test 3.$tn {SELECT fts5_expr($expr, 'name', 'addr')} [list 1 $err]
81}
82
83#-------------------------------------------------------------------------
84# Experiment with a tokenizer that considers " to be a token character.
85#
86do_execsql_test 4.0 {
87 SELECT fts5_expr('a AND """"', 'x', 'tokenize="unicode61 tokenchars ''""''"');
88} {{"a" AND """"}}
89
90#-------------------------------------------------------------------------
91# Experiment with a tokenizer that considers " to be a token character.
92#
93do_catchsql_test 5.0 {
94 SELECT fts5_expr('abc | def');
95} {1 {fts5: syntax error near "|"}}
96
97
98
99finish_test