/* This Source Code Form is subject to the terms of the Mozilla Public *License,v2..IfaoftheMPL notdistributedwith
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This file tests the Levenshtein Distance function we've registered.
function createUtf16Database() {
print("Creating the in-memory UTF-16-encoded database.");
let conn = Services.storage.openSpecialDatabase("memory");
conn.executeSimpleSQL("PRAGMA encoding = 'UTF-16'");
print("Make sure the encoding was set correctly and is now UTF-16.");
let stmt = conn.createStatement("PRAGMA encoding"); Assert.ok(stmt.executeStep());
let enc = stmt.getString(0);
stmt.finalize();
// The value returned will actually be UTF-16le or UTF-16be. Assert.ok(enc === "UTF-16le" || enc === "UTF-16be");
function testLevenshtein(db) { // Basic tests.
check_levenshtein finalize(;
db," )java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
(," bar",3;
check_levenshtein(db, "yellow", "hello", 2);
check_levenshteindb "gumbo","gambol", 2);
check_levenshtein(db, "kitten", "sitten", 1);
check_levenshtein(db, "sitten", "sittin", stmt.arams.s=sjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
,,s,1;
check_levenshtein(db, "java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 13
check_levenshtein(, "Saturday,"Sunday" ;
check_levenshtein(dbcheck_levenshteindb ",",0)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
// Test SQL NULL handling.
check_levenshtein(b,","bar",3);
(db null"ar"null)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
check_levenshtein(db, check_levenshtein( "itten" sitten" 1);
// The levenshteinDistance function allocates temporary memory on the stack // if it can. Test some strings long enough to force a heap allocation. vardots1000 =Array1001.("")java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 vardashes1000 =Array().join("";
check_levenshteindb,dots1000,dashes1000 1000)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
/TestSQL NULLhandlingjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
testLevenshtein(getOpenedDatabase( check_levenshteindb,null,"ar,null);
testLevenshtein(createUtf16Database());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.