1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibJS: Support all line terminators (LF, CR, LS, PS)

https://tc39.es/ecma262/#sec-line-terminators
This commit is contained in:
Linus Groh 2020-10-21 22:16:45 +01:00 committed by Andreas Kling
parent 5043c4a3e5
commit 15642874f3
8 changed files with 161 additions and 29 deletions

View file

@ -0,0 +1,53 @@
/*
These tests deliberately produce syntax errors to check what line the parser thinks we're on.
PLEASE MAKE SURE TO NOT LET YOUR EDITOR REMOVE THE LS/PS LINE TERMINATORS!
*/
test("LINE FEED is a line terminator", () => {
expect(() => {
Function("\n\n@");
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
});
test("CARRIAGE RETURN is a line terminator", () => {
expect(() => {
Function("\r\r@");
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
});
test("LINE SEPARATOR is a line terminator", () => {
expect(() => {
Function(`@`);
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
});
test("PARAGRAPH SEPARATOR is a line terminator", () => {
expect(() => {
Function(`@`);
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
});
test("CR LF is counted as only one line terminator", () => {
expect(() => {
Function("\r\n\r\n@");
}).toThrowWithMessage(SyntaxError, "line: 3, column: 1");
});
test("LF/CR are not allowed in string literal", () => {
expect(() => {
Function(`"
"`);
}).toThrowWithMessage(SyntaxError, "Unexpected token UnterminatedStringLiteral");
});
test("LS/PS are allowed in string literal", () => {
expect(`""`).toEval();
expect(`""`).toEval();
});
test("line terminators can be mixed (but please don't)", () => {
expect(() => {
Function(`\r\\r\n\n\r@`);
}).toThrowWithMessage(SyntaxError, "line: 7, column: 1");
});