Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  test_JsonSchema.js

  Sprache: JAVA
 

/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */


const { JsonSchema } = ChromeUtils.importESModule(
  "resource://gre/modules/JsonSchema.sys.mjs"
);

add_task(function test_basicSchema() {
  info("Testing validation of a basic schema");
  const schema = {
    type: "object",
    properties: {
      id: { type: "number" },
    },
    required: ["id"],
  };

  const validator = new JsonSchema.Validator(schema);

  Assert.deepEqual(
    JsonSchema.validate({ id: 123 }, schema),
    { valid: true, errors: [] },
    "Validation of basic schemas with validate()"
  );

  Assert.deepEqual(
    validator.validate({ id: 123 }, schema),
    { valid: true, errors: [] },
    "Validation of basic schemas with Validator"
  );

  Assert.ok(
    !JsonSchema.validate({}, schema).valid,
    "Validation of basic schemas with validate()"
  );
  Assert.ok(
    !validator.validate({}).valid,
    "Validation of basic schemas with Validator"
  );
});

add_task(function test_mozUrlFormat() {
  info("Testing custom string format 'moz-url-format'");
  const schema = {
    type: "string",
    format: "moz-url-format",
  };

  {
    const obj = "https://www.mozilla.org/%LOCALE%/";
    Assert.deepEqual(
      JsonSchema.validate(obj, schema),
      { valid: true, errors: [] },
      "Substitution of a valid variable validates"
    );
  }

  {
    const obj = "https://mozilla.org/%BOGUS%/";

    Assert.equal(
      Services.urlFormatter.formatURL(obj),
      obj,
      "BOGUS is an invalid variable for the URL formatter service"
    );

    Assert.ok(
      !JsonSchema.validate(obj, { type: "string", format: "uri" }).valid,
      "A moz-url-format string does not validate as a URI"
    );

    Assert.deepEqual(
      JsonSchema.validate(obj, schema),
      {
        valid: false,
        errors: [
          {
            instanceLocation: "#",
            keyword: "format",
            keywordLocation: "#/format",
            error: `String does not match format "moz-url-format".`,
          },
        ],
      },
      "Substitution of an invalid variable does not validate"
    );
  }
});

Messung V0.5 in Prozent
C=92 H=93 G=92

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik