Skip to content

Commit

Permalink
Add tests for Hashbang comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bfarias-godaddy committed Dec 3, 2018
1 parent 31e654a commit 3ddcec6
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/language/comments/hashbang-eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---
esid: pending
description: >
Hashbang comments should be available in Script evaluator contexts.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
---*/

eval('#!\n');
23 changes: 23 additions & 0 deletions test/language/comments/hashbang-function-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*---
esid: pending
description: >
Hashbang comments should not be allowed in function evaluator contexts.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [module]
---*/
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_',''));
assert.throws(SyntaxError, () => ctor('#!\n_'));
assert.throws(SyntaxError, () => new ctor('#!\n_',''));
assert.throws(SyntaxError, () => new ctor('#!\n_'));
}
10 changes: 10 additions & 0 deletions test/language/comments/hashbang-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!
/*---
esid: pending
description: >
Hashbang comments should be allowed in Modules.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [module]
---*/
15 changes: 15 additions & 0 deletions test/language/comments/hashbang-multi-line-comment.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
10 changes: 10 additions & 0 deletions test/language/comments/hashbang-no-line-separator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---
esid: pending
description: >
Hashbang comments should not require a newline afterwards
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
---*/

eval('#!');
10 changes: 10 additions & 0 deletions test/language/comments/hashbang-not-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! 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]
---*/

14 changes: 14 additions & 0 deletions test/language/comments/hashbang-preceding-directive-prologue.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
13 changes: 13 additions & 0 deletions test/language/comments/hashbang-preceding-empty-statement.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
14 changes: 14 additions & 0 deletions test/language/comments/hashbang-preceding-hashbang.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
14 changes: 14 additions & 0 deletions test/language/comments/hashbang-preceding-line-comment.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
14 changes: 14 additions & 0 deletions test/language/comments/hashbang-preceding-multi-line-comment.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
13 changes: 13 additions & 0 deletions test/language/comments/hashbang-preceding-whitespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
/*---
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]
negative:
phase: parse
type: SyntaxError
---*/
15 changes: 15 additions & 0 deletions test/language/comments/hashbang-statement-block.js
Original file line number Diff line number Diff line change
@@ -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]
negative:
phase: parse
type: SyntaxError
---*/
{
#!
}
11 changes: 11 additions & 0 deletions test/language/comments/hashbang-use-strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!"use strict"
/*---
esid: pending
description: >
Hashbang comments should not be interpretted and should not generate DirectivePrologues.
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
---*/

with ({}) {}

0 comments on commit 3ddcec6

Please sign in to comment.