mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Use assertNotReached() in tests
This commit is contained in:
parent
92a9fe0e49
commit
b9415dc0e9
Notes:
sideshowbarker
2024-07-19 07:37:53 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b9415dc0e92 Pull-request: https://github.com/SerenityOS/serenity/pull/1782
8 changed files with 36 additions and 27 deletions
|
@ -6,17 +6,15 @@ try {
|
|||
assert(Boolean.prototype.toString.call(true) === "true");
|
||||
assert(Boolean.prototype.toString.call(false) === "false");
|
||||
|
||||
let error = null;
|
||||
try {
|
||||
Boolean.prototype.toString.call("foo");
|
||||
} catch (err) {
|
||||
error = err;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e instanceof Error);
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "Not a Boolean");
|
||||
}
|
||||
|
||||
assert(error instanceof Error);
|
||||
assert(error.name === "TypeError");
|
||||
assert(error.message === "Not a Boolean");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (err) {
|
||||
console.log("FAIL: " + err);
|
||||
|
|
|
@ -6,17 +6,15 @@ try {
|
|||
assert(Boolean.prototype.valueOf.call(true) === true);
|
||||
assert(Boolean.prototype.valueOf.call(false) === false);
|
||||
|
||||
let error = null;
|
||||
try {
|
||||
Boolean.prototype.valueOf.call("foo");
|
||||
} catch (err) {
|
||||
error = err;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e instanceof Error);
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "Not a Boolean");
|
||||
}
|
||||
|
||||
assert(error instanceof Error);
|
||||
assert(error.name === "TypeError");
|
||||
assert(error.message === "Not a Boolean");
|
||||
|
||||
console.log("PASS");
|
||||
} catch (err) {
|
||||
console.log("FAIL: " + err);
|
||||
|
|
|
@ -26,7 +26,7 @@ try {
|
|||
|
||||
try {
|
||||
Object.defineProperty(o, "bar", { value: "xx", enumerable: false });
|
||||
assert(false);
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e.name === "TypeError");
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ try {
|
|||
try {
|
||||
var b = true;
|
||||
b();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "true is not a function");
|
||||
|
@ -10,6 +11,7 @@ try {
|
|||
try {
|
||||
var n = 100 + 20 + 3;
|
||||
n();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "123 is not a function");
|
||||
|
@ -18,6 +20,7 @@ try {
|
|||
try {
|
||||
var o = {};
|
||||
o.a();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "undefined is not a function");
|
||||
|
@ -25,6 +28,7 @@ try {
|
|||
|
||||
try {
|
||||
Math();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "[object MathObject] is not a function");
|
||||
|
@ -32,6 +36,7 @@ try {
|
|||
|
||||
try {
|
||||
new Math();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "[object MathObject] is not a constructor");
|
||||
|
@ -39,6 +44,7 @@ try {
|
|||
|
||||
try {
|
||||
new isNaN();
|
||||
assertNotReached();
|
||||
} catch(e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "function isNaN() {\n [NativeFunction]\n} is not a constructor");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
try {
|
||||
try {
|
||||
Math.abs(-20) = 40;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e.name === "ReferenceError");
|
||||
assert(e.message === "Invalid left-hand side in assignment");
|
||||
|
@ -8,6 +9,7 @@ try {
|
|||
|
||||
try {
|
||||
512 = 256;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e.name === "ReferenceError");
|
||||
assert(e.message === "Invalid left-hand side in assignment");
|
||||
|
@ -15,6 +17,7 @@ try {
|
|||
|
||||
try {
|
||||
"hello world" = "another thing?";
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e.name === "ReferenceError");
|
||||
assert(e.message === "Invalid left-hand side in assignment");
|
||||
|
|
|
@ -2,6 +2,7 @@ var a = "foo";
|
|||
|
||||
switch (a + "bar") {
|
||||
case 1:
|
||||
assertNotReached();
|
||||
break;
|
||||
case "foobar":
|
||||
case 2:
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
try {
|
||||
throw 1;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e === 1);
|
||||
}
|
||||
|
||||
try {
|
||||
throw [99];
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(typeof e === "object");
|
||||
assert(e.length === 1);
|
||||
|
@ -13,10 +15,12 @@ try {
|
|||
|
||||
function foo() {
|
||||
throw "hello";
|
||||
assertNotReached();
|
||||
}
|
||||
|
||||
try {
|
||||
foo();
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e === "hello");
|
||||
}
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
try {
|
||||
|
||||
const ConstantValue = 1;
|
||||
const constantValue = 1;
|
||||
try {
|
||||
ConstantValue = 2;
|
||||
} catch (e) {
|
||||
constantValue = 2;
|
||||
assertNotReached();
|
||||
} catch (e) {
|
||||
assert(e.name === "TypeError");
|
||||
assert(e.message === "Assignment to constant variable");
|
||||
assert(ConstantValue === 1);
|
||||
assert(constantValue === 1);
|
||||
}
|
||||
|
||||
// Make sure we can define new constants in inner scopes.
|
||||
//
|
||||
const ConstantValue2 = 1;
|
||||
|
||||
do
|
||||
{
|
||||
const ConstantValue2 = 2;
|
||||
}
|
||||
while (false)
|
||||
const constantValue2 = 1;
|
||||
do {
|
||||
const constantValue2 = 2;
|
||||
assert(constantValue2 === 2);
|
||||
} while (false);
|
||||
assert(constantValue2 === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue