/ Artifact Content
Login

Artifact 24bb398086eca6d8d3dab64d383d5bb2dd4ff681:


# 2009 November 28
#
# 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.
#
#***********************************************************************
#
# This file implements tests to verify the "testable statements" in the
# fts3.in document.
#

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

ifcapable !fts3 {
  finish_test
  return
}
source $testdir/fts3_common.tcl

# Procs used to make the tests in this file easier to read.
#
proc ddl_test {tn ddl} {
  uplevel [list do_write_test e_fts3-$tn sqlite_master $ddl]
}
proc write_test {tn tbl sql} {
  uplevel [list do_write_test e_fts3-$tn $tbl $sql]
}
proc read_test {tn sql result} {
  uplevel [list do_select_test e_fts3-$tn $sql $result]
}

foreach DO_MALLOC_TEST {0 1 2} {

db close
file delete -force test.db test.db-journal
sqlite3 db test.db
if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 }

##########################################################################
# Test the example CREATE VIRTUAL TABLE statements in section 1.1 
# of fts3.in.
#
ddl_test   1.1.1 {CREATE VIRTUAL TABLE data USING fts3()}
read_test  1.1.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0}

ddl_test   1.2.1 {
  CREATE VIRTUAL TABLE pages USING fts3(title, keywords, body)
}
read_test  1.2.2 {
  PRAGMA table_info(pages)
} {0 title {} 0 {} 0 1 keywords {} 0 {} 0 2 body {} 0 {} 0}

ddl_test   1.3.1 {
  CREATE VIRTUAL TABLE mail USING fts3(
      subject VARCHAR(256) NOT NULL,
      body TEXT CHECK(length(body)<10240)
  )
}
read_test  1.3.2 {
  PRAGMA table_info(mail)
} {0 subject {} 0 {} 0 1 body {} 0 {} 0}

# A very large string. Used to test if the constraint on column "body" of
# table "mail" is enforced (it should not be - FTS3 tables do not support
# constraints).
set largetext [string repeat "the quick brown fox " 5000]
write_test 1.3.3 mail_content { INSERT INTO mail VALUES(NULL, $largetext) }
read_test  1.3.4 {
  SELECT subject IS NULL, length(body) FROM mail
} [list 1 100000]

ddl_test   1.4.1 {
  CREATE VIRTUAL TABLE papers USING fts3(author, document, tokenize=porter)
}
read_test  1.4.2 {
  PRAGMA table_info(papers)
} {0 author {} 0 {} 0 1 document {} 0 {} 0}

ddl_test   1.5.1 {
  CREATE VIRTUAL TABLE simpledata USING fts3(tokenize=simple)
}
read_test  1.5.2 {
  PRAGMA table_info(simpledata)
} {0 content {} 0 {} 0}

ddl_test   1.6.1 {DROP TABLE data}
ddl_test   1.6.2 {DROP TABLE pages}
ddl_test   1.6.3 {DROP TABLE mail}
ddl_test   1.6.4 {DROP TABLE papers}
ddl_test   1.6.5 {DROP TABLE simpledata}
read_test  1.6.6 {SELECT * FROM sqlite_master} {}

# The following is not one of the examples in section 1.1. It tests 
# specifying an FTS3 table with no module arguments using a slightly
# different syntax.
ddl_test   1.7.1 {CREATE VIRTUAL TABLE data USING fts3;}
read_test  1.7.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0}
ddl_test   1.7.3 {DROP TABLE data}

##########################################################################

##########################################################################
# Test the example in section 5 (custom tokenizers).
#
ddl_test   2.1.1 { CREATE VIRTUAL TABLE simple USING fts3(tokenize=simple) } 
write_test 2.1.2 simple_content { 
  INSERT INTO simple VALUES('Right now they''re very frustrated')
}
read_test  2.1.3 {SELECT docid FROM simple WHERE simple MATCH 'Frustrated'} {1} 
read_test  2.1.4 {SELECT docid FROM simple WHERE simple MATCH 'Frustration'} {}

ddl_test   2.2.1 { CREATE VIRTUAL TABLE porter USING fts3(tokenize=porter) } 
write_test 2.2.2 porter_content { 
  INSERT INTO porter VALUES('Right now they''re very frustrated')
}
read_test  2.2.3 {SELECT docid FROM porter WHERE porter MATCH 'Frustrated'} {1} 
read_test  2.2.4 {SELECT docid FROM porter WHERE porter MATCH 'Frustration'} {1}

##########################################################################
# Test the examples in section 4 (auxillary functions).
#
ddl_test   3.1.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) }

write_test 3.1.2 mail_content { 
  INSERT INTO mail VALUES(
    'hello world', 'This message is a hello world message.');
}
write_test 3.1.3 mail_content { 
  INSERT INTO mail VALUES(
    'urgent: serious', 'This mail is seen as a more serious mail');
}

read_test 3.1.4 { 
  SELECT offsets(mail) FROM mail WHERE mail MATCH 'world';
} {{0 0 6 5 1 0 24 5}}
read_test 3.1.5 { 
  SELECT offsets(mail) FROM mail WHERE mail MATCH 'message'
} {{1 0 5 7 1 0 30 7}}
read_test 3.1.6 { 
  SELECT offsets(mail) FROM mail WHERE mail MATCH '"serious mail"'
} {{1 0 28 7 1 1 36 4}}

ddl_test 3.2.1 { CREATE VIRTUAL TABLE text USING fts3() }

write_test 3.2.2 text_content {
  INSERT INTO text VALUES('
    During 30 Nov-1 Dec, 2-3oC drops. Cool in the upper portion, minimum temperature 14-16oC and cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6-12oC. Northeasterly winds 15-30 km/hr. After that, temperature increases. Northeasterly winds 15-30 km/hr.
  ');
}

read_test 3.2.3 {
  SELECT snippet(text) FROM text WHERE text MATCH 'cold'
} {{<b>...</b> elsewhere, minimum temperature 17-20oC. <b>Cold</b> to very <b>cold</b> on mountaintops, minimum <b>...</b>}}

read_test 3.2.4 {
  SELECT snippet(text, '[', ']', '...') FROM text WHERE text MATCH '"min* tem*"'
} {{... 2-3oC drops. Cool in the upper portion, [minimum] [temperature] 14-16oC and cool elsewhere, [minimum] ...}}

#break
}

finish_test