From e82da3033050c2ab0835f6074bdc04733a4f08f0 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 23 Jan 2019 00:46:32 +0100 Subject: [PATCH] test(ts-estree): add test scenario for unix/windows/mac EOL --- packages/typescript-estree/tests/lib/parse.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/typescript-estree/tests/lib/parse.ts b/packages/typescript-estree/tests/lib/parse.ts index 74f02d03792c..ad1f85a4f82c 100644 --- a/packages/typescript-estree/tests/lib/parse.ts +++ b/packages/typescript-estree/tests/lib/parse.ts @@ -99,4 +99,41 @@ describe('parse()', () => { ); }); }); + + describe('line endings', () => { + const config: ParserOptions = { + comment: true, + tokens: true, + range: true, + loc: true + }; + + function validateLineEndings (code: string) { + const result = parser.parse(`\`${code}\``, config) as any; + expect(result.body[0].type).toBe( + parser.AST_NODE_TYPES.ExpressionStatement + ); + expect(result.body[0].expression.type).toBe( + parser.AST_NODE_TYPES.TemplateLiteral + ); + expect(result.body[0].expression.quasis[0].type).toBe( + parser.AST_NODE_TYPES.TemplateElement + ); + const value = result.body[0].expression.quasis[0].value; + expect(value.raw).toBe(code); + expect(value.cooked).toBe(code); + } + + it('should parse unix EOL correctly', () => { + validateLineEndings(`\n\n\n\n`); + }); + + it('should parse windows EOL correctly', () => { + validateLineEndings(`\r\n\r\n\r\n`); + }); + + it('should parse mac EOL correctly', () => { + validateLineEndings(`\r\r\r`); + }); + }); });