xref: /sqlite-3.40.0/ext/fts5/test/fts5eb.test (revision 7d44b22d)
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
13source [file join [file dirname [info script]] fts5_common.tcl]
14set testprefix fts5eb
15
16# If SQLITE_ENABLE_FTS5 is defined, omit this file.
17ifcapable !fts5 {
18  finish_test
19  return
20}
21
22proc do_syntax_error_test {tn expr err} {
23  set ::se_expr $expr
24  do_catchsql_test $tn {SELECT fts5_expr($se_expr)} [list 1 $err]
25}
26
27proc do_syntax_test {tn expr res} {
28  set ::se_expr $expr
29  do_execsql_test $tn {SELECT fts5_expr($se_expr)} [list $res]
30}
31
32foreach {tn expr res} {
33  1  {abc}                            {"abc"}
34  2  {abc ""}                         {"abc"}
35  3  {""}                             {}
36  4  {abc OR ""}                      {"abc" OR ""}
37  5  {abc NOT ""}                     {"abc" NOT ""}
38  6  {abc AND ""}                     {"abc" AND ""}
39  7  {"" OR abc}                      {"" OR "abc"}
40  8  {"" NOT abc}                     {"" NOT "abc"}
41  9  {"" AND abc}                     {"" AND "abc"}
42  10 {abc + "" + def}                 {"abc" + "def"}
43  11 {abc "" def}                     {"abc" AND "def"}
44  12 {r+e OR w}                       {"r" + "e" OR "w"}
45
46  13 {a AND b NOT c}                  {"a" AND ("b" NOT "c")}
47  14 {a OR b NOT c}                   {"a" OR ("b" NOT "c")}
48  15 {a NOT b AND c}                  {("a" NOT "b") AND "c"}
49  16 {a NOT b OR c}                   {("a" NOT "b") OR "c"}
50
51  17 {a AND b OR c}                   {("a" AND "b") OR "c"}
52  18 {a OR b AND c}                   {"a" OR ("b" AND "c")}
53
54} {
55  do_execsql_test 1.$tn {SELECT fts5_expr($expr)} [list $res]
56}
57
58do_catchsql_test 2.1 {
59  SELECT fts5_expr()
60} {1 {wrong number of arguments to function fts5_expr}}
61
62do_catchsql_test 2.2 {
63  SELECT fts5_expr_tcl()
64} {1 {wrong number of arguments to function fts5_expr_tcl}}
65
66do_catchsql_test 2.3 {
67  SELECT fts5_expr('')
68} {1 {fts5: syntax error near ""}}
69
70do_catchsql_test 2.4 {
71  SELECT fts5_expr(NULL)
72} {1 {fts5: syntax error near ""}}
73
74do_catchsql_test 2.5 {
75  SELECT fts5_expr(NULL, NULL)
76} {1 {parse error in ""}}
77
78for {set i 0} {$i < 255} {incr i} {
79  do_test 2.6.$i {
80    lindex [catchsql {sELECT fts5_expr(NULL, char($i));}] 0
81  } 1
82}
83
84do_execsql_test 3.0 {
85  CREATE VIRTUAL TABLE e1 USING fts5(text, tokenize = 'porter unicode61');
86  INSERT INTO e1 VALUES ('just a few words with a / inside');
87}
88do_execsql_test 3.1 {
89  SELECT rowid, bm25(e1) FROM e1 WHERE e1 MATCH '"just"' ORDER BY rank;
90} {1 -1e-06}
91do_execsql_test 3.2 {
92  SELECT rowid FROM e1 WHERE e1 MATCH '"/" OR "just"'
93} 1
94do_execsql_test 3.3 {
95  SELECT rowid, bm25(e1) FROM e1 WHERE e1 MATCH '"/" OR "just"' ORDER BY rank;
96} {1 -1e-06}
97
98
99
100finish_test
101