diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-18 19:09:17 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-18 20:35:23 +0100 |
commit | 299c3069c1024514de26c697bfcee8b75d906762 (patch) | |
tree | 25124b5841a3148660b467ec85541c04959d49ee | |
parent | 2e9f665bda041ad2e9ee70ecabbaf96a18a7a2ec (diff) | |
download | serenity-299c3069c1024514de26c697bfcee8b75d906762.zip |
LibJS/Tests: Use eval() for toEvalTo(), not Function()
Since we have had eval() for a while now, we can finally use it here -
this allows us to get rid of the confusing return statements in tested
source code.
5 files changed, 8 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Tests/automatic-semicolon-insertion.js b/Userland/Libraries/LibJS/Tests/automatic-semicolon-insertion.js index 998b0b6622..32db0b81f3 100644 --- a/Userland/Libraries/LibJS/Tests/automatic-semicolon-insertion.js +++ b/Userland/Libraries/LibJS/Tests/automatic-semicolon-insertion.js @@ -37,7 +37,7 @@ test("break/continue, variable declaration, do-while, and return asi", () => { 1; var curly/* semicolon inserted here */} -return foo();`; +foo();`; expect(source).toEvalTo(undefined); }); @@ -55,7 +55,7 @@ for (let i = 0; i < 5; ++i) { counter++; } -return counter;`; +counter;`; expect(source).toEvalTo(5); }); diff --git a/Userland/Libraries/LibJS/Tests/comments-basic.js b/Userland/Libraries/LibJS/Tests/comments-basic.js index 3dbe6aec1e..101e520a29 100644 --- a/Userland/Libraries/LibJS/Tests/comments-basic.js +++ b/Userland/Libraries/LibJS/Tests/comments-basic.js @@ -7,7 +7,7 @@ var i = 0; i++; */ /**/ i++; -return i;`; +i;`; expect(source).toEvalTo(1); }); @@ -22,7 +22,7 @@ i++; --> i++; /**/ --> i++; j --> i++; -return i;`; +i;`; expect(source).toEvalTo(2); }); diff --git a/Userland/Libraries/LibJS/Tests/operators/ternary-basic.js b/Userland/Libraries/LibJS/Tests/operators/ternary-basic.js index c0f68fdf83..81e808cdef 100644 --- a/Userland/Libraries/LibJS/Tests/operators/ternary-basic.js +++ b/Userland/Libraries/LibJS/Tests/operators/ternary-basic.js @@ -16,5 +16,5 @@ test("object values", () => { }); test("issue #4409, '?.' followed by decimal digit", () => { - expect("return false?.1:.2").toEvalTo(0.2); + expect("false?.1:.2").toEvalTo(0.2); }); diff --git a/Userland/Libraries/LibJS/Tests/test-common-tests.js b/Userland/Libraries/LibJS/Tests/test-common-tests.js index a857d327bb..1801bb078d 100644 --- a/Userland/Libraries/LibJS/Tests/test-common-tests.js +++ b/Userland/Libraries/LibJS/Tests/test-common-tests.js @@ -333,13 +333,11 @@ test("toEval", () => { expect("function foo() { return 1; }; foo();").toEval(); }); -// FIXME: Will have to change when this matcher changes to use the -// "eval" function test("toEvalTo", () => { expect("let a = 1").toEvalTo(); expect("let a = 1").toEvalTo(undefined); - expect("return 10").toEvalTo(10); - expect("return 10").not.toEvalTo(5); + expect("10").toEvalTo(10); + expect("10").not.toEvalTo(5); expect(() => { expect("*^&%%").not.toEvalTo(); diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js index 911d194dd9..3c0eec4f11 100644 --- a/Userland/Libraries/LibJS/Tests/test-common.js +++ b/Userland/Libraries/LibJS/Tests/test-common.js @@ -354,7 +354,7 @@ class ExpectationError extends Error { let result; try { - result = new Function(this.target)(); + result = eval(this.target); } catch (e) { throw new ExpectationError(); } |