modernc.org/cc@v1.0.1/v2/testdata/_sqlite/ext/fts5/test/fts5eb.test (about)

     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  
    13  source [file join [file dirname [info script]] fts5_common.tcl]
    14  set testprefix fts5eb
    15  
    16  # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    17  ifcapable !fts5 {
    18    finish_test
    19    return
    20  }
    21  
    22  proc 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  
    27  proc 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  
    32  foreach {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  
    58  do_catchsql_test 2.1 {
    59    SELECT fts5_expr()
    60  } {1 {wrong number of arguments to function fts5_expr}}
    61  
    62  do_catchsql_test 2.1 {
    63    SELECT fts5_expr_tcl()
    64  } {1 {wrong number of arguments to function fts5_expr_tcl}}
    65  
    66  
    67  do_execsql_test 3.0 {
    68    CREATE VIRTUAL TABLE e1 USING fts5(text, tokenize = 'porter unicode61');
    69    INSERT INTO e1 VALUES ("just a few words with a / inside");
    70  }
    71  do_execsql_test 3.1 {
    72    SELECT rowid, bm25(e1) FROM e1 WHERE e1 MATCH '"just"' ORDER BY rank;
    73  } {1 -1e-06}
    74  do_execsql_test 3.2 {
    75    SELECT rowid FROM e1 WHERE e1 MATCH '"/" OR "just"'
    76  } 1
    77  do_execsql_test 3.3 {
    78    SELECT rowid, bm25(e1) FROM e1 WHERE e1 MATCH '"/" OR "just"' ORDER BY rank;
    79  } {1 -1e-06}
    80  
    81  
    82  
    83  finish_test