test_storage_ext_fts3.js (2739B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 // This file tests support for the fts3 (full-text index) module. 6 7 // Example statements in these tests are taken from the Full Text Index page 8 // on the SQLite wiki: http://www.sqlite.org/cvstrac/wiki?p=FullTextIndex 9 10 function test_table_creation() { 11 var msc = getOpenedUnsharedDatabase(); 12 13 msc.executeSimpleSQL( 14 "CREATE VIRTUAL TABLE recipe USING fts3(name, ingredients)" 15 ); 16 17 Assert.ok(msc.tableExists("recipe")); 18 } 19 20 function test_insertion() { 21 var msc = getOpenedUnsharedDatabase(); 22 23 msc.executeSimpleSQL( 24 "INSERT INTO recipe (name, ingredients) VALUES " + 25 "('broccoli stew', 'broccoli peppers cheese tomatoes')" 26 ); 27 msc.executeSimpleSQL( 28 "INSERT INTO recipe (name, ingredients) VALUES " + 29 "('pumpkin stew', 'pumpkin onions garlic celery')" 30 ); 31 msc.executeSimpleSQL( 32 "INSERT INTO recipe (name, ingredients) VALUES " + 33 "('broccoli pie', 'broccoli cheese onions flour')" 34 ); 35 msc.executeSimpleSQL( 36 "INSERT INTO recipe (name, ingredients) VALUES " + 37 "('pumpkin pie', 'pumpkin sugar flour butter')" 38 ); 39 40 var stmt = msc.createStatement("SELECT COUNT(*) FROM recipe"); 41 stmt.executeStep(); 42 43 Assert.equal(stmt.getInt32(0), 4); 44 45 stmt.reset(); 46 stmt.finalize(); 47 } 48 49 function test_selection() { 50 var msc = getOpenedUnsharedDatabase(); 51 52 var stmt = msc.createStatement( 53 "SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'" 54 ); 55 56 Assert.ok(stmt.executeStep()); 57 Assert.equal(stmt.getInt32(0), 3); 58 Assert.equal(stmt.getString(1), "broccoli pie"); 59 Assert.equal(stmt.getString(2), "broccoli cheese onions flour"); 60 61 Assert.ok(stmt.executeStep()); 62 Assert.equal(stmt.getInt32(0), 4); 63 Assert.equal(stmt.getString(1), "pumpkin pie"); 64 Assert.equal(stmt.getString(2), "pumpkin sugar flour butter"); 65 66 Assert.ok(!stmt.executeStep()); 67 68 stmt.reset(); 69 stmt.finalize(); 70 } 71 72 var tests = [test_table_creation, test_insertion, test_selection]; 73 74 function run_test() { 75 // It's extra important to start from scratch, since these tests won't work 76 // with an existing shared cache connection, so we do it even though the last 77 // test probably did it already. 78 cleanup(); 79 80 try { 81 for (var i = 0; i < tests.length; i++) { 82 tests[i](); 83 } 84 } finally { 85 // It's extra important to clean up afterwards, since later tests that use 86 // a shared cache connection will not be able to read the database we create, 87 // so we do this in a finally block to ensure it happens even if some of our 88 // tests fail. 89 cleanup(); 90 } 91 }