From 0c877a1283e1b36e6de61b7e345afae5e7f4981c Mon Sep 17 00:00:00 2001 From: Vincent LE GOFF Date: Sat, 13 Apr 2019 21:24:36 +0200 Subject: [PATCH] EOL add mixed detection (denoland/deno_std#325) Original: https://github.com/denoland/deno_std/commit/bb92c44c648844ba6fe0e1e038c87da2716f618b --- fs/eol.ts | 2 +- fs/eol_test.ts | 57 +++++++++++++++++++++++++++++++++++--------------- fs/test.ts | 2 +- test.ts | 3 +-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/fs/eol.ts b/fs/eol.ts index af5e81ead8..46babe406f 100644 --- a/fs/eol.ts +++ b/fs/eol.ts @@ -17,7 +17,7 @@ export function detect(content: string): EOL | null { if (!d || d.length === 0) { return null; } - const crlf = d.filter(x => x === EOL.CRLF); + const crlf = d.filter((x: string) => x === EOL.CRLF); if (crlf.length > 0) { return EOL.CRLF; } else { diff --git a/fs/eol_test.ts b/fs/eol_test.ts index eafdb697e5..94ca486275 100644 --- a/fs/eol_test.ts +++ b/fs/eol_test.ts @@ -9,24 +9,47 @@ const Mixedinput2 = "deno\r\nis not\nnode"; const LFinput = "deno\nis not\nnode"; const NoNLinput = "deno is not node"; -test(function detectCRLF() { - assertEquals(detect(CRLFinput), EOL.CRLF); +test({ + name: "[EOL] Detect CR LF", + fn() { + assertEquals(detect(CRLFinput), EOL.CRLF); + } }); -test(function detectLF() { - assertEquals(detect(LFinput), EOL.LF); + +test({ + name: "[EOL] Detect LF", + fn() { + assertEquals(detect(LFinput), EOL.LF); + } }); -test(function detectNoNewLine() { - assertEquals(detect(NoNLinput), null); + +test({ + name: "[EOL] Detect No New Line", + fn() { + assertEquals(detect(NoNLinput), null); + } }); -test(function testFormat() { - assertEquals(format(CRLFinput, EOL.LF), LFinput); - assertEquals(format(LFinput, EOL.LF), LFinput); - assertEquals(format(LFinput, EOL.CRLF), CRLFinput); - assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); - assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); - assertEquals(format(NoNLinput, EOL.CRLF), NoNLinput); - assertEquals(format(Mixedinput, EOL.CRLF), CRLFinput); - assertEquals(format(Mixedinput, EOL.LF), LFinput); - assertEquals(format(Mixedinput2, EOL.CRLF), CRLFinput); - assertEquals(format(Mixedinput2, EOL.LF), LFinput); + +test({ + name: "[EOL] Detect Mixed", + fn() { + assertEquals(detect(Mixedinput), EOL.CRLF); + assertEquals(detect(Mixedinput2), EOL.CRLF); + } +}); + +test({ + name: "[EOL] Format", + fn() { + assertEquals(format(CRLFinput, EOL.LF), LFinput); + assertEquals(format(LFinput, EOL.LF), LFinput); + assertEquals(format(LFinput, EOL.CRLF), CRLFinput); + assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); + assertEquals(format(CRLFinput, EOL.CRLF), CRLFinput); + assertEquals(format(NoNLinput, EOL.CRLF), NoNLinput); + assertEquals(format(Mixedinput, EOL.CRLF), CRLFinput); + assertEquals(format(Mixedinput, EOL.LF), LFinput); + assertEquals(format(Mixedinput2, EOL.CRLF), CRLFinput); + assertEquals(format(Mixedinput2, EOL.LF), LFinput); + } }); diff --git a/fs/test.ts b/fs/test.ts index dac0d350dd..cc9013eed7 100644 --- a/fs/test.ts +++ b/fs/test.ts @@ -3,8 +3,8 @@ import "./path/test.ts"; import "./walk_test.ts"; import "./globrex_test.ts"; import "./glob_test.ts"; -import "./eol_test.ts"; import "./exists_test.ts"; +import "./eol_test.ts"; import "./empty_dir_test.ts"; import "./ensure_dir_test.ts"; import "./ensure_file_test.ts"; diff --git a/test.ts b/test.ts index 9760b0f234..652ffcaacc 100755 --- a/test.ts +++ b/test.ts @@ -4,10 +4,9 @@ import "./colors/test.ts"; import "./datetime/test.ts"; import "./examples/test.ts"; import "./flags/test.ts"; -import "./io/test.ts"; import "./fs/test.ts"; -import "./io/test.ts"; import "./http/test.ts"; +import "./io/test.ts"; import "./log/test.ts"; import "./media_types/test.ts"; import "./multipart/test.ts";