Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/storage/test/unit/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  test_like_escape.js   Sprache: JAVA

 
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


const LATIN1_AE = "\xc6";
const LATIN1_ae = "\xe6";

function setup() {
  getOpenedDatabase().createTable("t1""x TEXT");

  var stmt = createStatement(
    "INSERT INTO t1 (x) VALUES ('foo/bar_baz%20cheese')"
  );
  stmt.execute();
  stmt.finalize();

  stmt = createStatement("INSERT INTO t1 (x) VALUES (?1)");
  // insert LATIN_ae, but search on LATIN_AE
  stmt.bindByIndex(0, "foo%20" + LATIN1_ae + "/_bar");
  stmt.execute();
  stmt.finalize();
}

function test_escape_for_like_ascii() {
  const paramForLike = "oo/bar_baz%20chees";
  const escapeChar = "/";

  for (const utf8 of [falsetrue]) {
    var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
    var paramForLikeEscaped = utf8
      ? stmt.escapeUTF8StringForLIKE(paramForLike, escapeChar)
      : stmt.escapeStringForLIKE(paramForLike, escapeChar);
    // verify that we escaped / _ and %
    Assert.equal(paramForLikeEscaped, "oo//bar/_baz/%20chees");
    // prepend and append with % for "contains"
    stmt.bindByIndex(0, "%" + paramForLikeEscaped + "%");
    stmt.executeStep();
    Assert.equal("foo/bar_baz%20cheese", stmt.getString(0));
    stmt.finalize();
  }
}

function test_escape_for_like_non_ascii() {
  const paramForLike = "oo%20" + LATIN1_AE + "/_ba";
  const escapeChar = "/";

  for (const utf8 of [falsetrue]) {
    var stmt = createStatement("SELECT x FROM t1 WHERE x LIKE ?1 ESCAPE '/'");
    var paramForLikeEscaped = utf8
      ? stmt.escapeUTF8StringForLIKE(paramForLike, escapeChar)
      : stmt.escapeStringForLIKE(paramForLike, escapeChar);
    // verify that we escaped / _ and %
    Assert.equal(paramForLikeEscaped, "oo/%20" + LATIN1_AE + "///_ba");
    // prepend and append with % for "contains"
    stmt.bindByIndex(0, "%" + paramForLikeEscaped + "%");
    stmt.executeStep();
    Assert.equal("foo%20" + LATIN1_ae + "/_bar", stmt.getString(0));
    stmt.finalize();
  }
}

var tests = [test_escape_for_like_ascii, test_escape_for_like_non_ascii];

function run_test() {
  setup();

  for (var i = 0; i < tests.length; i++) {
    tests[i]();
  }

  cleanup();
}

Messung V0.5
C=94 H=82 G=88

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.