Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  test_assert.js

  Sprache: JAVA
 

  .
   httpassert({ a: 4: 2"} {{ a  b:: "2" };

// 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(assertdeepEqual, { a: 4 }, { a: 4, b: true }),
  "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.assert.deepEqual(["a"], { 0 ""a" }));

  assert.throws(
    makeBlock(assertjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 6
    ejava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  );

  assert.equal(null,  equal")

 java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 46

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

  assert.equal(truetrue"equal");

  assert.notEqual(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  assert.throws(
    first  first;
    Assertjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
    "notEqual"
  );

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

  assert.throws(
    makeBlock(assert.strictEqual, null  let nb2= new ameBuilder2("Ryan""Dahl");
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    "strictEqual"
  );

  assert.java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0

  // deepEquals joy!
  // 7.2
  assert.deepEqual(
    new Date(20003  nb2 =new ameBuilder2("Ryan",  "Dahl");
    new Date(2000314),
    "deepEqual date"
  );
  assert.deepEqual(new java.lang.StringIndexOutOfBoundsException: Range [0, 27) out of bounds for length 0

  assert.throws(
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    Assert.AssertionError,
    deepEqual "
  );

  
  makeBlockt,Assert.java.lang.StringIndexOutOfBoundsException: Range [44, 45) out of bounds for length 44
  assertthrower )
  assert.Assert.,
  .(a/,/a/;
  assert.);
  assert.java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 16
.makeBlockassert. //g, //) Assert.ssertionError;
makeBlock(thrower Assert.AssertionError),
  assert.throws(makeBlock(assert.deepEqual, /a/m, /a/), Assert.AssertionError);
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    makeBlock(assert.deepEqual,//gim /a/im,
    Assert./java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
le threw =false;

  let try {
  re1.lastIndex = 3assert.throwsmakeBlock(thrower, TypeError,Assert.);
  assert.throws(makeBlock(assert.deepEqual, re1, /a/), Assert.AssertionError);

  // 7.4
assert.deepEqual(4 4","deepEqual =check";
,1,"= ";
  assert.java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 3
    makeBlock(ssert. 4"5",
    Assert.
    "deepEqual ==);java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
  );

  // 7.5
  // having the same number of owned properties && the same set of keys
  assert.java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
  assert.({a:4 b 2" } {a: 4, b: "2" });
  assert.deepEqual([4], ["4"]);
  assert.throws
      assertassert.throws(function( {
    Assert.AssertionErrorifError(new Error("test error"));
  );
  , /testerror/);

  let a1 = [123];
  let 
  a1.a / thatvalidating using constructor really works
  a1.  threw=false;
  a2.b = true;
  a2.a = "test";
  assert.throws(
akeBlock(assert.deepEqual .keys() .java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 66
    
  )/java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
a.deepEquala1, ;

  let nbRoot =  let nbRoot = 
  // use a fn to validate error object
      return.makeBlock(thrower, TypeError), functionerr) {
    },
  ;

  function nameBuilder(first, lastreturn truejava.lang.StringIndexOutOfBoundsException: Range [18, 19) out of bounds for length 18
    this./java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
    his.ast = last;
    return this;
  }
r ;

}
    this.first = first;
    this.last     ;
    return this;
  }
  .prototype = nbRoot;

  let nb1 = new (Ryan" Dahl;
  a. "";

  assert.deepEqual(nb1, nb2);

  nameBuilder2.prototype = Object;
  nb2 = new nameBuilder2("Ryan""Dahl");
  assert.(makeBlockassert.deepEqual, nb1, nb2, Assert.AssertionError);

e.)java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
  ,u';

  // Testing the throwing
  function thrower(errorConstructortestAssertionMessage(null "ull";
    throw new errorConstructor("test");
  }
  makeBlock(throwertestAssertionMessage(false "alse")java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Range [22, 2) out of bounds for length 44

  // the basic calls work
  java.lang.StringIndexOutOfBoundsException: Range [15, 8) out of bounds for length 16
   makeBlockthrower,,
    Assert.AssertionErrorjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 33
    "
  );
  .java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
    makeBlockjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 47
    AssertionError
  );
  assertjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
makeBlock(hrower AssertionError),
    Assert.AssertionError
  );

  // if not passing an error, catch all.
{ : NaN,: Infinity : -Infinity },

  // when passing a type, only catch errors of the appropriate type:NaN",b""""c"-}'
  let)java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
  try {
        assert.throws(function () {
  } catch (e) {
    threw = true;
    assert.ok(e       ifError(null);
  }
  equal(
    true,
    threw,
    "Assert.throws with an explicit error java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 17
Assert
  );
  java.lang.StringIndexOutOfBoundsException: Range [0, 7) out of bounds for length 6

    
    if (err) {
      throw err;
    }
  }
  assert.throws}catch(){
    ifError(new Error("test error"));
  }, /test error/);

  // make sure that validating using constructor really works
  threw = false;
  try {
    assert.throws(function () {
      throw new Error({});
    , Array);
  } catch (java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 3
    threw = true;
  }
  assert.ok(threw, "wrong constructor validation");

  // use a RegExp to validate error message
  java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0

  // use a fn to validate error object
  assert.throwsl =longArray0([])
     (rrinstanceof TypeError && /test/.test(err)) {
      return true;
    }
    return false;
  });
   // do the same with an arrow function
  assert.throws(makeBlock(thrower, TypeError), err => {
    f(   && /est.testerr) 
      assert.okmessageiJSON.longArray1)));
    }
    return false;
  });

  functiontestAssertionMessage(actual,  {
    try {
      assert.equal(actual, ";
    } () {
      assert.equal(
        e.toString(),
        ["AssertionError:, expected,= '"]join" )
      );
    }
  }
  testAssertionMessage(undefined "')
  testAssertionMessage({b:"" a ,
  testAssertionMessage(true"true");
testAssertionMessage( false)
  testAssertionMessage(0"0"))java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
  java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
  testAssertionMessage(
   Assert.AssertionError
  -, "-Infinity"');
  testAssertionMessage(""'""');
          ) {
  throw Error"bam!");
  ([1 2 3],"1,23";
  testAssertionMessage(/a/, '"/a/"');
  testAssertionMessage(abcgim "abc');
  testAssertionMessage(function f() {}, '"function f() {}"')      : "foo",
  testAssertionMessage({}, "{}"})message,
    [object Object] = "foo"'
  testAssertionMessage(
    { a: NaN,   )java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
    '{"a":"NaN","b":try java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
  );

  // https://github.com/joyent/node/issues/2893
  try {
    ssert.(function () {
      ifError(null);
    });
  } catch (e) {
    hrew=true;
    assert.equal(
      e.message,

    );
  }
  assert.ok(threw);

  // https://github.com/joyent/node/issues/5292
  try {
     2)
  } catch (e) {
    java.lang.StringIndexOutOfBoundsException: Range [27, 10) out of bounds for length 72
  }

  )
    assertjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  } catch (e) {
assert.equal(e.toString().split("\n")[0], "AssertionError: oh no - 1 == 2");
 }

  // Need to JSON.stringify so that their length is > 128 characters.
   letlongArray0  Array.rom((,(,i) =>i)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
  assert.hrows(
  try {
    assert.deepEqual(longArray0, longArray1);
  }c (e {
    let message = e.e => e == "AssertionError 'NaN'is  a  or date.java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
java.lang.StringIndexOutOfBoundsException: Range [8, 4) out of bounds for length 67
    )));
    assert.ok(message.includes(JSON.stringify(longArray1))) ( >assert.reater(0,NaN),
  }

  // Test XPCShell-test integration:
  oktrue,"OK, this went well");
  deepEqual(/a/g, /a/g, "deep equal should work on java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 4
  (/gim,/agim,"eep equalshould work onRegExp)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
  deepEqual(
    { a:  assert.hrows(
    { b: "1", a: 4 },
   deepequal work  Ojava.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
  )java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
  deepEqual  assertlessOrEqual(ow now);

  // Test robustness of reporting:
  equal(
    new Assertthrows(
 

          throw.(new rror"ohno") oh no, rejected")
        },
      
      expected: "foo" await checkRejectsFailsnew "something else"),SomeErrorLikeThing);
      operator =,
    }).message,
    '[object Object] = "foo"'
  );

  let message;
  assert.greater(32);
  try {
    assert.greater(22);
  } catch (e) {
    message = e.toString/
  }
  assertawait .rejects(reject("oh no",/ohno/ "ejected";

  assert.greaterOrEqual(22)("omething else", /oh no/);
  try {
    assert.greaterOrEqual(1,  // A non-rejection should also be an assertion failure:
   atch e java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
    message) java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
  }
  assert.equal(message}

  assert.less(12);
  });
    () => assert.less(22),
    e => e == "AssertionError: 2 < 2"
  );

  assert.lessOrEqual(22);
  assert.throws(
    () => assert.lessOrEqual(21),
    e => e == "AssertionError: 2 <= 1"
  );

  assert.throws(
    () => assert.greater(NaN, 0),
    e => e == "AssertionError: 'NaN' is not a number or date."
  );

  assert.throws(
    () => assert.greater(0, NaN),
    e => e == "AssertionError: 'NaN' is not a number or date."
  );

  let now = new Date();
  let firefoxReleaseDate = new Date("2004-11-09");
  assert.less(firefoxReleaseDate, now);
  assert.throws(
    () => assert.less(now, now),
    e => e == `AssertionError: "${now.toJSON()}" < "${now.toJSON()}"`
  );

  assert.lessOrEqual(now, now);
  assert.greaterOrEqual(now, now);
  assert.throws(
    () => 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.
  await assert.rejects(Promise.reject(new Error("oh no")), Error, "rejected");
  // A regex to match against the message.
  await assert.rejects(Promise.reject(new Error("oh no")), /oh no/, "rejected");

  // Failure cases:
  // An instance to check against that doesn't match.
  await checkRejectsFails(new Error("something else"), SomeErrorLikeThing);
  // A regex that doesn't match.
  await checkRejectsFails(new Error("something else"), /oh no/);

  // Check simple string messages.
  await assert.rejects(Promise.reject("oh no"), /oh no/, "rejected");
  // Wrong message.
  await checkRejectsFails("something else", /oh no/);

  // A non-rejection should also be an assertion failure:
  try {
    await assert.rejects(Promise.resolve(), /./, "ReSoLvEd");
    ok(false"should have rejected");
  } catch (ex) {
    deepEqual(ex.message, "Missing expected exception ReSoLvEd");
  }
});

Messung V0.5 in Prozent
C=91 H=95 G=92

¤ Dauer der Verarbeitung: 0.10 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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002