summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-13 14:11:09 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-13 16:28:50 +0200
commitb9415dc0e9279d2e86fb82fdcae25d934f33b212 (patch)
tree94651f90b01ebac1242685cde4fe31e598c2e88b /Libraries/LibJS
parent92a9fe0e49b490e2a255d687f855f97fcab7ae3d (diff)
downloadserenity-b9415dc0e9279d2e86fb82fdcae25d934f33b212.zip
LibJS: Use assertNotReached() in tests
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r--Libraries/LibJS/Tests/Boolean.prototype.toString.js12
-rw-r--r--Libraries/LibJS/Tests/Boolean.prototype.valueOf.js12
-rw-r--r--Libraries/LibJS/Tests/Object.defineProperty.js2
-rw-r--r--Libraries/LibJS/Tests/function-TypeError.js6
-rw-r--r--Libraries/LibJS/Tests/invalid-lhs-in-assignment.js3
-rw-r--r--Libraries/LibJS/Tests/switch-basic-2.js1
-rw-r--r--Libraries/LibJS/Tests/throw-basic.js4
-rw-r--r--Libraries/LibJS/Tests/variable-declaration.js23
8 files changed, 36 insertions, 27 deletions
diff --git a/Libraries/LibJS/Tests/Boolean.prototype.toString.js b/Libraries/LibJS/Tests/Boolean.prototype.toString.js
index dd4848b796..9a8846af4b 100644
--- a/Libraries/LibJS/Tests/Boolean.prototype.toString.js
+++ b/Libraries/LibJS/Tests/Boolean.prototype.toString.js
@@ -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);
diff --git a/Libraries/LibJS/Tests/Boolean.prototype.valueOf.js b/Libraries/LibJS/Tests/Boolean.prototype.valueOf.js
index af7fffaeab..7cfba10495 100644
--- a/Libraries/LibJS/Tests/Boolean.prototype.valueOf.js
+++ b/Libraries/LibJS/Tests/Boolean.prototype.valueOf.js
@@ -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);
diff --git a/Libraries/LibJS/Tests/Object.defineProperty.js b/Libraries/LibJS/Tests/Object.defineProperty.js
index f27a2332be..d63e89beb2 100644
--- a/Libraries/LibJS/Tests/Object.defineProperty.js
+++ b/Libraries/LibJS/Tests/Object.defineProperty.js
@@ -26,7 +26,7 @@ try {
try {
Object.defineProperty(o, "bar", { value: "xx", enumerable: false });
- assert(false);
+ assertNotReached();
} catch (e) {
assert(e.name === "TypeError");
}
diff --git a/Libraries/LibJS/Tests/function-TypeError.js b/Libraries/LibJS/Tests/function-TypeError.js
index 2d411c2221..cd7870c952 100644
--- a/Libraries/LibJS/Tests/function-TypeError.js
+++ b/Libraries/LibJS/Tests/function-TypeError.js
@@ -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");
diff --git a/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js b/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
index 7257c87e29..323ed9bb66 100644
--- a/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
+++ b/Libraries/LibJS/Tests/invalid-lhs-in-assignment.js
@@ -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");
diff --git a/Libraries/LibJS/Tests/switch-basic-2.js b/Libraries/LibJS/Tests/switch-basic-2.js
index 10934fdf71..d492b1d3ab 100644
--- a/Libraries/LibJS/Tests/switch-basic-2.js
+++ b/Libraries/LibJS/Tests/switch-basic-2.js
@@ -2,6 +2,7 @@ var a = "foo";
switch (a + "bar") {
case 1:
+ assertNotReached();
break;
case "foobar":
case 2:
diff --git a/Libraries/LibJS/Tests/throw-basic.js b/Libraries/LibJS/Tests/throw-basic.js
index 6751d01d38..3b5106ec43 100644
--- a/Libraries/LibJS/Tests/throw-basic.js
+++ b/Libraries/LibJS/Tests/throw-basic.js
@@ -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");
}
diff --git a/Libraries/LibJS/Tests/variable-declaration.js b/Libraries/LibJS/Tests/variable-declaration.js
index ef634867c9..461a46ecd2 100644
--- a/Libraries/LibJS/Tests/variable-declaration.js
+++ b/Libraries/LibJS/Tests/variable-declaration.js
@@ -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) {