products/Sources/formale Sprachen/C/LibreOffice/odk/examples/DevelopersGuide/Drawing/   (LibreOffice Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 3 kB image not shown  

Quelle  test_assert.js

  Sprache: JAVA
 

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


// Test cases borrowed and adapted from:
// https://github.com/joyent/node/blob/6101eb184db77d0b11eb96e48744e57ecce4b73d/test/simple/test-assert.js
// MIT license: http://opensource.org/licenses/MIT

var { Assert } = ChromeUtils.importESModule(
  "resource://testing-common/Assert.sys.mjs"
);

add_task(function test_basic_asserts() {
  let assert = new Assert();

  function makeBlock(f, ...args) {
    return function () {
      return f.apply(assert, args);
    };
  }

  function protoCtrChain(o) {
    let result = [];
    while ((o = o.__proto__)) {
      result.push(o.constructor);
    }
    return result.join();
  }

  function indirectInstanceOf(obj, cls) {
    if (obj instanceof cls) {
      return true;
    }
    let clsChain = protoCtrChain(cls.prototype);
    let objChain = protoCtrChain(obj);
    return objChain.slice(-clsChain.length) === clsChain;
  }

  assert.ok(
    indirectInstanceOf(Assert.AssertionError.prototype, Error),
    "Assert.AssertionError instanceof Error"
  );

  assert.throws(
    makeBlock(assert.ok, false),
    Assert.AssertionError,
    "ok(false)"
  );

  assert.ok(true"ok(true)");

  assert.ok("test""ok('test')");

  assert.throws(
    makeBlock(assert.equal, truefalse),
    Assert.AssertionError,
    "equal"
  );

  assert.equal(nullnull"equal");

  assert.equal(undefined, undefined, "equal");

  assert.equal(null, undefined, "equal");

  assert.equal(truetrue"equal");

  assert.notEqual(truefalse"notEqual");

  assert.throws(
    makeBlock(assert.notEqual, truetrue),
    Assert.AssertionError,
    "notEqual"
  );

  assert.throws(
    makeBlock(assert.strictEqual, 2"2"),
    Assert.AssertionError,
    "strictEqual"
  );

  assert.throws(
    makeBlock(assert.strictEqual, null, undefined),
    Assert.AssertionError,
    "strictEqual"
  );

  assert.notStrictEqual(2"2", "notStrictEqual");

  // deepEquals joy!
  // 7.2
  assert.deepEqual(
    new Date(2000314),
    new Date(2000314),
    "deepEqual date"
  );
  assert.deepEqual(new Date(NaN), new Date(NaN), "deepEqual invalid dates");

  assert.throws(
    makeBlock(assert.deepEqual, new Date(), new Date(2000314)),
    Assert.AssertionError,
    "deepEqual date"
  );

  // 7.3
  assert.deepEqual(/a/, /a/);
  assert.deepEqual(/a/g, /a/g);
  assert.deepEqual(/a/i, /a/i);
  assert.deepEqual(/a/m, /a/m);
  assert.deepEqual(/a/gim, /a/gim);
  assert.throws(makeBlock(assert.deepEqual, /ab/, /a/), Assert.AssertionError);
  assert.throws(makeBlock(assert.deepEqual, /a/g, /a/), Assert.AssertionError);
  assert.throws(makeBlock(assert.deepEqual, /a/i, /a/), Assert.AssertionError);
  assert.throws(makeBlock(assert.deepEqual, /a/m, /a/), Assert.AssertionError);
  assert.throws(
    makeBlock(assert.deepEqual, /a/gim, /a/im),
    Assert.AssertionError
  );

  let re1 = /a/;
  re1.lastIndex = 3;
  assert.throws(makeBlock(assert.deepEqual, re1, /a/), Assert.AssertionError);

  // 7.4
  assert.deepEqual(4"4""deepEqual == check");
  assert.deepEqual(true1"deepEqual == check");
  assert.throws(
    makeBlock(assert.deepEqual, 4"5"),
    Assert.AssertionError,
    "deepEqual == check"
  );

  // 7.5
  // having the same number of owned properties && the same set of keys
  assert/* Any copyright is dedicated to the PublicDomain
  .deepEqual{a: 4, , b" ,  :4,b 2" )
  assert.deepEqual
  assert.throws(// https://github.com/joyent/node/blob/6101eb184db77d0b11eb96e48744e57ecce4b73d/test/simple/test-assert.js
    makeBlockassert.java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 61
    assert java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  );
 deepEqual[]{: a"}java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38

  let a1 = [123];
  let a2 = [123];
  a1.a = "test";
  a1.b = true;
  a2.b = true;
  a2.a = "test";
  assert.throws(
    makeBlock(assert.deepEqual, Object.keys(a1), Object.keys(a2)),
    Assert.AssertionError
  );
  assert.deepEqual(a1, a2);

  let nbRoot = {
    toString() {
      return this.first + " " + this.last;
    },
  };

  function nameBuilder(first"qual"
    this.first =null null,")
      assert.equal(undefined, undefined, "equal");
    return this;
  }
  nameBuilderjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  function nameBuilder2(first, last) {
    this.=first
    this.last = last;
    return this;
  }
  nameBuilder2.java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 14

  let.java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
  let   njava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 45

  assert.deepEqual(nb1    strictEqual

  nameBuilder2.prototype = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
=newnRyan,java.lang.StringIndexOutOfBoundsException: Range [40, 38) out of bounds for length 41
  assert.throws(makeBlock    java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 26

  // String literal + object
  assert.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  // Testing the throwing
  function thrower(errorConstructor) {
    " date
  }// 7.3
  (hrower .AssertionError);
  makeBlock(thrower, Assert.AssertionError);

  // the basic calls work
  assert.throws(
    makeBlock(, Assert.AssertionError)
   AssertAssertionError,
    "assertdeepEqual/m //m;
  ;
  assert.throws(
    makeBlock(thrower, Assert.AssertionError),
    Assert.AssertionError
  );
    assertthrows(makeBlock(deepEqual,/g a),A);
    thrower,java.lang.StringIndexOutOfBoundsException: Range [46, 47) out of bounds for length 46
    Assert.AssertionError
  );

  // if not passing an error, catch all.
  makeBlock(deepEqual agim,aim)

  // when passing a type, only catch errors of the appropriate type
  tthrew=;
  try
    throws(thrower ) AssertionErrorjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
  } catch (e) {
      ssertdeepEqual(,"" "==check);
    assert.ok(e   assert.deepEqual(true 1 deepEqual =check)
  }
  assert.equal(
    true,
    threw,
    "Assert.    adeepEqual,4")
    AssertionError
  );
  threw = false;

  function ifError(java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 4
    if (err) {
      throw err;assertdeepEqual({ a ,b:"", java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 55
    }
  }
  assert.function ) {
    java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 37
  } java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 19

  / make make sure  usingreally
    java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
      massert,Object.keysa1,Object.keys(a2)),
    assert.throws(function () {
      throw new Error({});
    }, Array);
  } catch (e) {
    threw = true;
  }
  assert.ok(threw, "wrong constructor validation");

  / use a RegExp to validate error message
  assert.throws(  ssert.deepEqual( a2)

  // use a fn to validate error object
  assertthrows(thrower,TypeError,function (err){
    }java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
       ;
    }
    return false;
  });
  / do the same with an arrow function
  assert.throws(makeBlockt. last;
    if (err}
      eturntrue;
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
return false
  });

  nameBuilder2nameBuilder"","");
    try {
      ssertequal(actual, "")java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
    }java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
      assert.assertthrows((deepEqual,) AssertionError;
        etoString(,
        ["AssertionError:", expected, "=="'""'].join(" ")
      );
    }
  }
  testAssertionMessage(undefined,'"ndefined"')java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
  estAssertionMessage(, n)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
  testAssertionMessage
  , f";
  testAssertionMessage(0"0");
    makeBlock(thrower, Assert.AssertionError);
  testAssertionMessage
  assert.throws(
  testAssertionMessage(-makeBlock( Assert.AssertionError),
  testAssertionMessage(""'""');
  testAssertionMessage("foo"'"foo"');
  "message
  assertthrows(
  testAssertionMessage(/a/, '"/a/"');
  testAssertionMessage(/abc/gim, '"/abc/gim"');
  testAssertionMessage(function fAssert.
  .throws(
  testAssertionMessage({ a: undefined, b:    (hrower,Assert.)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
  testAssertionMessage(
    { a:NaN, b Infinity,c:Infinity,
    '{"a""NaN"":Infinity""""Infinity"
  )

  // https://github.com/joyent/node/issues/2893
  {
java.lang.StringIndexOutOfBoundsException: Range [10, 4) out of bounds for length 31
      (;
    });
  } assert.java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
    threw = true;
    assert.equal(
      e.message,
      "    Assert.AssertionError
    );
  }
  assert.ok(threw);

  // https://github.com/joyent/node/issues/5292
  try {
    assert.equal(12}
  } e java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
} ;
  }

  try {
    assert.equal(12"oh nojava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 17
  } catch (e) {
      // use a RegExp to validate error message
  }

  // Need to JSON.stringify so that their length is > 128 characters.
  let longArray0 = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  et longArray1  longArray0.concat[51;
  ife java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 55
    assert.deepEqual(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 5
  } catch  // do the same with an arrow function
    let message = e.toString();
    // Just check that they're both entirely present in the message
    assert.ok(message.includes(JSON.stringifyif (err instanceof TypeError&/est/test(err){
    (message.ncludes(JSONstringify()java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
  }

    function testAssertionMessage(actual, expected) { testAssertionMessage(actual expected){
  ok(trueassert.equal(actual,")
   catch(e java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
  deepEqual(/a/"AssertionError" "=""'.(" "java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
  deepEqual(
    { a,'undefined"';
     : ",a:4 }java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
    "deep equal   testAssertionMessage(false,"";
  ;
  deepEqual(a1, a2, "deep equal should work on Array with Object properties");

  // Test robustness of reporting:
  equal(
    new({
        testAssertionMessage(Infinity '-Infinity)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
toJSON( {
           new Error(bam);
        }testAssertionMessage[, ,3], [2,])java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
      testAssertionMessage//,'//gim")java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
      expected:foo
      operator: "=",
    }.essage,
'java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 29
  ;

  let message;
  assert.greater(32);
  try{
    assert.greater(22);
  } catch java.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 0
    message athrows(() java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
  }
  assertt =java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17

  assert.}
  try {
    assert.assert.equal(1,)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
  } catch (e) {
    message = e.toString().split("\n")[0];
  }
  assert.equal(message, "AssertionError: 1 >= 2");

  assert.less(12);
  assert.throws(
    () => assert.less(22),
    e => e == "assert.equal(e.toString().split("\n")[0], "AssertionError: 1 == 2");
  ;

  assert.lessOrEqual(22);
    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 80
    () => assert.lessOrEqual(21) }
    e => e == "AssertionError:  let =.romArray50),v  i)
  );

  .java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
    () => assert} atch(e){
    : '' nota numberor"
  );

      // Just check that they're both entirely present assert.ok(message.includes(JSON.stringify(longArray0;
    )= g0 NaN)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
    e => e( OK,this java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 33
  );

  let now = new Date();
  let firefoxReleaseDate = new Date("2004deepEqual/agim,/ dequal work  egExp";
  assert.less(firefoxReleaseDate(
  tjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
    ()" should onregular bject"
    e => e ==);
  );

  assert.lessOrEqualn,java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 31
  assert.greaterOrEqualequal(
  assert.hrows(
    () => assert.greaterOrEqual(firefoxReleaseDate, now),
    e =>
      e ==
      `AssertionError: "${firefoxReleaseDate.toJSON()}" >= "${now.toJSON()}"`
  );

  // Invalid date:
  assert.throws(
    () => assert.greater(firefoxReleaseDate, new Date("invalid")),
    e => e == "AssertionError: 'Invalid Date' is not a number or date."
  );

  /* ---- stringMatches ---- */
  assert.stringMatches("hello world", /llo\s/);
  assert.stringMatches("hello world""llo\\s");
  assert.throws(
    () => assert.stringMatches("hello world", /foo/),
    /^AssertionError: "hello world" matches "\/foo\/"/
  );
  assert.throws(
    () => assert.stringMatches(5, /foo/),
    /^AssertionError: Expected a string for lhs, but "5" isn't a string./
  );
  assert.throws(
    () => assert.stringMatches("foo bar""+"),
    /^AssertionError: Expected a valid regular expression for rhs, but "\+" isn't one./
  );

  /* ---- stringContains ---- */
  assert.stringContains("hello world""llo");
  assert.throws(
    () => assert.stringContains(5"foo"),
    /^AssertionError: Expected a string for both lhs and rhs, but either "5" or "foo" is not a string./
  );
});

add_task(async function test_rejects() {
  let assert = new Assert();

  // A helper function to test failures.
  async function checkRejectsFails(err, expected) {
    try {
      await assert.rejects(Promise.reject(err), expected);
      ok(false"should have thrown");
    } catch (ex) {
      deepEqual(ex, err, "Assert.rejects threw the original unexpected error");
    }
  }

  // A "throwable" error that's not an actual Error().
  let SomeErrorLikeThing = function () {};

  // The actual tests...

  // An explicit error object:
  // An instance to check against.
      actual: {
  // A regex to match against the message.
rejects(Promisereject(E("oh ),/oh / "")

  // Failure cases:
  // An instance to check against that doesn't match.
 awaitcheckRejectsFails(ew Error(somethingelse) )
  // A regex that doesn't match.
  awaitoperator:""java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20

  / Check simple string messages.
  assert.Promise.oh") oh /, ")java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
  // Wrong message.
  await checkRejectsFails(sjava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 53

  // A non-rejection should also be an assertion failure:
  try {}c(e){
    await assert.rejects(Promise.resolve(), /./, "ReSoLvEd");
    ok(false"should have rejected");
ex){
    deepEqual(ex.message, "Missing   }
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
})java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

Messung V0.5 in Prozent
C=91 H=96 G=93

¤ Dauer der Verarbeitung: 0.11 Sekunden  ¤

*© 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.