From da8ef2e7796bf70abbbf73fb524330a9dc95dc88 Mon Sep 17 00:00:00 2001 From: Bradley Farias <bfarias@godaddy.com> Date: Mon, 3 Dec 2018 15:55:42 -0600 Subject: [PATCH] Add tests for Hashbang comments --- .../comments/hashbang-encoded-bang.js | 10 +++++++++ .../comments/hashbang-encoded-hash.js | 10 +++++++++ .../comments/hashbang-encoded-hashbang.js | 10 +++++++++ test/language/comments/hashbang-eval.js | 10 +++++++++ .../comments/hashbang-function-body.js | 14 ++++++++++++ .../comments/hashbang-function-constructor.js | 22 +++++++++++++++++++ test/language/comments/hashbang-module.js | 10 +++++++++ .../comments/hashbang-multi-line-comment.js | 15 +++++++++++++ .../comments/hashbang-no-line-separator.js | 11 ++++++++++ test/language/comments/hashbang-not-empty.js | 11 ++++++++++ .../hashbang-preceding-directive-prologue.js | 14 ++++++++++++ .../hashbang-preceding-empty-statement.js | 13 +++++++++++ .../comments/hashbang-preceding-hashbang.js | 14 ++++++++++++ .../hashbang-preceding-line-comment.js | 14 ++++++++++++ .../hashbang-preceding-multi-line-comment.js | 14 ++++++++++++ .../comments/hashbang-preceding-whitespace.js | 13 +++++++++++ .../comments/hashbang-statement-block.js | 15 +++++++++++++ test/language/comments/hashbang-use-strict.js | 12 ++++++++++ 18 files changed, 232 insertions(+) create mode 100644 test/language/comments/hashbang-encoded-bang.js create mode 100644 test/language/comments/hashbang-encoded-hash.js create mode 100644 test/language/comments/hashbang-encoded-hashbang.js create mode 100644 test/language/comments/hashbang-eval.js create mode 100644 test/language/comments/hashbang-function-body.js create mode 100644 test/language/comments/hashbang-function-constructor.js create mode 100644 test/language/comments/hashbang-module.js create mode 100644 test/language/comments/hashbang-multi-line-comment.js create mode 100644 test/language/comments/hashbang-no-line-separator.js create mode 100644 test/language/comments/hashbang-not-empty.js create mode 100644 test/language/comments/hashbang-preceding-directive-prologue.js create mode 100644 test/language/comments/hashbang-preceding-empty-statement.js create mode 100644 test/language/comments/hashbang-preceding-hashbang.js create mode 100644 test/language/comments/hashbang-preceding-line-comment.js create mode 100644 test/language/comments/hashbang-preceding-multi-line-comment.js create mode 100644 test/language/comments/hashbang-preceding-whitespace.js create mode 100644 test/language/comments/hashbang-statement-block.js create mode 100644 test/language/comments/hashbang-use-strict.js diff --git a/test/language/comments/hashbang-encoded-bang.js b/test/language/comments/hashbang-encoded-bang.js new file mode 100644 index 0000000000..0d8f8d9fab --- /dev/null +++ b/test/language/comments/hashbang-encoded-bang.js @@ -0,0 +1,10 @@ +#\u0021 +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-encoded-hash.js b/test/language/comments/hashbang-encoded-hash.js new file mode 100644 index 0000000000..6d29abd2fc --- /dev/null +++ b/test/language/comments/hashbang-encoded-hash.js @@ -0,0 +1,10 @@ +\u0023! +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-encoded-hashbang.js b/test/language/comments/hashbang-encoded-hashbang.js new file mode 100644 index 0000000000..629bda6a78 --- /dev/null +++ b/test/language/comments/hashbang-encoded-hashbang.js @@ -0,0 +1,10 @@ +\u0023\u0021 +/*--- +esid: pending +description: > + Hashbang comments should not be allowed to have encoded characters +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ diff --git a/test/language/comments/hashbang-eval.js b/test/language/comments/hashbang-eval.js new file mode 100644 index 0000000000..8f69cd81bc --- /dev/null +++ b/test/language/comments/hashbang-eval.js @@ -0,0 +1,10 @@ +/*--- +esid: pending +description: > + Hashbang comments should be available in Script evaluator contexts. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ + +assert.sameValue(eval('#!\n'), undefined); diff --git a/test/language/comments/hashbang-function-body.js b/test/language/comments/hashbang-function-body.js new file mode 100644 index 0000000000..2bb5130902 --- /dev/null +++ b/test/language/comments/hashbang-function-body.js @@ -0,0 +1,14 @@ +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be allowed within function bodies. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ +function fn() {#! +} diff --git a/test/language/comments/hashbang-function-constructor.js b/test/language/comments/hashbang-function-constructor.js new file mode 100644 index 0000000000..fdc3f85bab --- /dev/null +++ b/test/language/comments/hashbang-function-constructor.js @@ -0,0 +1,22 @@ +/*--- +esid: pending +description: > + Hashbang comments should not be allowed in function evaluator contexts. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +---*/ +const AsyncFunction = (async function (){}).constructor; +const GeneratorFunction = (function *(){}).constructor; +const AsyncGeneratorFunction = (async function *(){}).constructor; +for (ctor of [ + Function, + AsyncFunction, + GeneratorFunction, + AsyncGeneratorFunction, +]) { + assert.throws(SyntaxError, () => ctor('#!\n_',''), `${ctor.name} Call argument`); + assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} Call body`); + assert.throws(SyntaxError, () => new ctor('#!\n_',''), `${ctor.name} Construct argument`); + assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} Construct body`); +} diff --git a/test/language/comments/hashbang-module.js b/test/language/comments/hashbang-module.js new file mode 100644 index 0000000000..ea30c700f6 --- /dev/null +++ b/test/language/comments/hashbang-module.js @@ -0,0 +1,10 @@ +#! +/*--- +esid: pending +description: > + Hashbang comments should be allowed in Modules. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [module] +---*/ diff --git a/test/language/comments/hashbang-multi-line-comment.js b/test/language/comments/hashbang-multi-line-comment.js new file mode 100644 index 0000000000..27bc551e4f --- /dev/null +++ b/test/language/comments/hashbang-multi-line-comment.js @@ -0,0 +1,15 @@ +#!/* +these characters should not be considered within a comment +*/ +/*--- +esid: pending +description: > + Hashbang comments should not interpret multi-line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-no-line-separator.js b/test/language/comments/hashbang-no-line-separator.js new file mode 100644 index 0000000000..824d903d9f --- /dev/null +++ b/test/language/comments/hashbang-no-line-separator.js @@ -0,0 +1,11 @@ +/*--- +esid: pending +description: > + Hashbang comments should not require a newline afterwards +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ + +eval('#!'); diff --git a/test/language/comments/hashbang-not-empty.js b/test/language/comments/hashbang-not-empty.js new file mode 100644 index 0000000000..b005a3f290 --- /dev/null +++ b/test/language/comments/hashbang-not-empty.js @@ -0,0 +1,11 @@ +#! these characters should be treated as a comment +/*--- +esid: pending +description: > + Hashbang comments should be allowed in Scripts and should not be required to be empty. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ + diff --git a/test/language/comments/hashbang-preceding-directive-prologue.js b/test/language/comments/hashbang-preceding-directive-prologue.js new file mode 100644 index 0000000000..edd975cfb7 --- /dev/null +++ b/test/language/comments/hashbang-preceding-directive-prologue.js @@ -0,0 +1,14 @@ +"use strict" +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at start of source texts and should not be preceded by DirectivePrologues. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-empty-statement.js b/test/language/comments/hashbang-preceding-empty-statement.js new file mode 100644 index 0000000000..bff2aa6d8f --- /dev/null +++ b/test/language/comments/hashbang-preceding-empty-statement.js @@ -0,0 +1,13 @@ +;#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by empty statements. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-hashbang.js b/test/language/comments/hashbang-preceding-hashbang.js new file mode 100644 index 0000000000..27d079ddf5 --- /dev/null +++ b/test/language/comments/hashbang-preceding-hashbang.js @@ -0,0 +1,14 @@ +#! +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by Hashbang comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-line-comment.js b/test/language/comments/hashbang-preceding-line-comment.js new file mode 100644 index 0000000000..365b5dc4dd --- /dev/null +++ b/test/language/comments/hashbang-preceding-line-comment.js @@ -0,0 +1,14 @@ +// +#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-multi-line-comment.js b/test/language/comments/hashbang-preceding-multi-line-comment.js new file mode 100644 index 0000000000..5145019f04 --- /dev/null +++ b/test/language/comments/hashbang-preceding-multi-line-comment.js @@ -0,0 +1,14 @@ +/* +*/#! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by multi-line comments. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-preceding-whitespace.js b/test/language/comments/hashbang-preceding-whitespace.js new file mode 100644 index 0000000000..7be73bd36a --- /dev/null +++ b/test/language/comments/hashbang-preceding-whitespace.js @@ -0,0 +1,13 @@ + #! +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be preceded by whitespace. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ \ No newline at end of file diff --git a/test/language/comments/hashbang-statement-block.js b/test/language/comments/hashbang-statement-block.js new file mode 100644 index 0000000000..62ce7af3cc --- /dev/null +++ b/test/language/comments/hashbang-statement-block.js @@ -0,0 +1,15 @@ +/*--- +esid: pending +description: > + Hashbang comments should only be allowed at the start of source texts and should not be allowed within blocks. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +negative: + phase: parse + type: SyntaxError +---*/ +{ + #! +} \ No newline at end of file diff --git a/test/language/comments/hashbang-use-strict.js b/test/language/comments/hashbang-use-strict.js new file mode 100644 index 0000000000..d8a7a5e8b9 --- /dev/null +++ b/test/language/comments/hashbang-use-strict.js @@ -0,0 +1,12 @@ +#!"use strict" +/*--- +esid: pending +description: > + Hashbang comments should not be interpretted and should not generate DirectivePrologues. +info: | + HashbangComment:: + #! SingleLineCommentChars[opt] +flags: [raw] +---*/ + +with ({}) {} -- GitLab