Browse Source

LibJS: Add tests for exception if assignment LHS is invalid

Barney Wilks 5 years ago
parent
commit
4f48fcdb94
1 changed files with 26 additions and 0 deletions
  1. 26 0
      Libraries/LibJS/Tests/invalid-lhs-in-assignment.js

+ 26 - 0
Libraries/LibJS/Tests/invalid-lhs-in-assignment.js

@@ -0,0 +1,26 @@
+try {
+    try {
+        Math.abs(-20) = 40;
+    } catch (e) {
+        assert(e.name === "ReferenceError");
+        assert(e.message === "Invalid left-hand side in assignment");
+    }
+
+    try {
+        512 = 256;
+    } catch (e) {
+        assert(e.name === "ReferenceError");
+        assert(e.message === "Invalid left-hand side in assignment");
+    }
+
+    try {
+        "hello world" = "another thing?";
+    } catch (e) {
+        assert(e.name === "ReferenceError");
+        assert(e.message === "Invalid left-hand side in assignment");
+    }
+
+    console.log("PASS");
+} catch (e) {
+    console.log("FAIL: " + e);
+}