From 2661a8810898548e26e98600a00e42e3ad1c1c84 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 14 Jun 2021 15:59:04 +0430 Subject: [PATCH] LibJS: Add a test file for generator function parsing Note that the yield-from expression tests are skipped for now since they're not implemented yet. --- .../LibJS/Tests/syntax/generators.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Userland/Libraries/LibJS/Tests/syntax/generators.js diff --git a/Userland/Libraries/LibJS/Tests/syntax/generators.js b/Userland/Libraries/LibJS/Tests/syntax/generators.js new file mode 100644 index 00000000000..70d45aa532a --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/syntax/generators.js @@ -0,0 +1,23 @@ +describe("parsing freestanding generators", () => { + test("simple", () => { + expect(`function* foo() {}`).toEval(); + expect(`function *foo() {}`).toEval(); + expect(`function + *foo() {}`).toEval(); + }); + test("yield expression", () => { + expect(`function* foo() { yield; }`).toEval(); + expect(`function* foo() { yield (yield); }`).toEval(); + expect(`function* foo() { yield (yield foo); }`).toEval(); + expect(`function foo() { yield; }`).toEval(); + expect(`function foo() { yield 3; }`).not.toEval(); + }); + test.skip("yield-from expression", () => { + expect(`function* foo() { yield *bar; }`).toEval(); + expect(`function* foo() { yield *(yield); }`).toEval(); + expect(`function* foo() { yield + *bar; }`).not.toEval(); + expect(`function foo() { yield + *bar; }`).toEval(); + }); +});