# 2012 December 18
#
# 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.
#
#*************************************************************************
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix fts5create

do_execsql_test 1.1 { 
  CREATE TABLE t1(a, b, c);
}

do_execsql_test 1.2 { 
  CREATE INDEX ft1 ON t1 USING fts5();
  SELECT * FROM sqlite_master;
} {
  table t1 t1  2 "CREATE TABLE t1(a, b, c)"
  index ft1 t1 3 "CREATE INDEX ft1 ON t1 USING fts5()"
}

do_execsql_test 1.3 { 
  DROP INDEX ft1;
  SELECT * FROM sqlite_master;
} {
  table t1 t1  2 "CREATE TABLE t1(a, b, c)"
}

do_execsql_test 1.4 { 
  CREATE INDEX ft1 ON t1 USING fts5();
  SELECT * FROM sqlite_master;
} {
  table t1 t1  2 "CREATE TABLE t1(a, b, c)"
  index ft1 t1 3 "CREATE INDEX ft1 ON t1 USING fts5()"
}

do_execsql_test 1.5 { 
  DROP INDEX ft1;
  SELECT * FROM sqlite_master;
} {
  table t1 t1  2 "CREATE TABLE t1(a, b, c)"
}

do_catchsql_test 1.6 { 
  CREATE UNIQUE INDEX ft2 ON t1 USING fts5();
} {1 {USING fts5 index may not be UNIQUE}}

#-------------------------------------------------------------------------
#
reset_db

do_execsql_test 2.1 {
  CREATE TABLE t2(x, y);
  CREATE INDEX fulltext ON t2 USING fts5(tokenizer=simple);
  SELECT * FROM sqlite_master;
} {
  table t2 t2 2 {CREATE TABLE t2(x, y)}
  index fulltext t2 3 {CREATE INDEX fulltext ON t2 USING fts5(tokenizer=simple)}
}

do_catchsql_test 2.2 { 
  DROP INDEX fulltext; 
  CREATE INDEX ft ON t2 USING fts5(tukenizer=simple);
} {1 {unrecognized argument: "tukenizer"}}

do_catchsql_test 2.3 { 
  CREATE INDEX ft ON t2 USING fts5("a b c");
} {1 {unrecognized argument: "a b c"}}

do_catchsql_test 2.4 {
  CREATE INDEX ft ON t2 USING fts5(tokenizer="nosuch");
} {1 {no such tokenizer: "nosuch"}}

#-------------------------------------------------------------------------
#
reset_db

do_execsql_test 3.1 {
  CREATE TABLE t1(a, b, c, PRIMARY KEY(a));
  INSERT INTO t1 VALUES(1, 'a b c d', 'e f g h');
  INSERT INTO t1 VALUES(2, 'e f g h', 'a b c d');
}

do_execsql_test 3.2 {
  CREATE INDEX ft ON t1 USING fts5();
  PRAGMA fts_check(ft);
} {ok}


finish_test


