From ebe7b558962807c184cf88d20a2052be1d07b57c Mon Sep 17 00:00:00 2001 From: LE GOFF Vincent Date: Sun, 7 Apr 2019 11:32:22 +0200 Subject: [PATCH 1/2] EOL move to encoding Add mixed detection deleted double entry for io/test --- {fs => encoding}/eol.ts | 2 +- encoding/eol_test.ts | 55 +++++++++++++++++++++++++++++++++++++++++ encoding/test.ts | 2 ++ fs/eol_test.ts | 32 ------------------------ fs/test.ts | 1 - test.ts | 4 +-- 6 files changed, 60 insertions(+), 36 deletions(-) rename {fs => encoding}/eol.ts (92%) create mode 100644 encoding/eol_test.ts create mode 100644 encoding/test.ts delete mode 100644 fs/eol_test.ts diff --git a/fs/eol.ts b/encoding/eol.ts similarity index 92% rename from fs/eol.ts rename to encoding/eol.ts index af5e81ead824..46babe406f99 100644 --- a/fs/eol.ts +++ b/encoding/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/encoding/eol_test.ts b/encoding/eol_test.ts new file mode 100644 index 000000000000..94ca4862758e --- /dev/null +++ b/encoding/eol_test.ts @@ -0,0 +1,55 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import { test } from "../testing/mod.ts"; +import { assertEquals } from "../testing/asserts.ts"; +import { format, detect, EOL } from "./eol.ts"; + +const CRLFinput = "deno\r\nis not\r\nnode"; +const Mixedinput = "deno\nis not\r\nnode"; +const Mixedinput2 = "deno\r\nis not\nnode"; +const LFinput = "deno\nis not\nnode"; +const NoNLinput = "deno is not node"; + +test({ + name: "[EOL] Detect CR LF", + fn() { + assertEquals(detect(CRLFinput), EOL.CRLF); + } +}); + +test({ + name: "[EOL] Detect LF", + fn() { + assertEquals(detect(LFinput), EOL.LF); + } +}); + +test({ + name: "[EOL] Detect No New Line", + fn() { + assertEquals(detect(NoNLinput), null); + } +}); + +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/encoding/test.ts b/encoding/test.ts new file mode 100644 index 000000000000..16f6aece5cae --- /dev/null +++ b/encoding/test.ts @@ -0,0 +1,2 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import "./eol_test.ts"; diff --git a/fs/eol_test.ts b/fs/eol_test.ts deleted file mode 100644 index eafdb697e507..000000000000 --- a/fs/eol_test.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; -import { assertEquals } from "../testing/asserts.ts"; -import { format, detect, EOL } from "./eol.ts"; - -const CRLFinput = "deno\r\nis not\r\nnode"; -const Mixedinput = "deno\nis not\r\nnode"; -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(function detectLF() { - assertEquals(detect(LFinput), EOL.LF); -}); -test(function detectNoNewLine() { - 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); -}); diff --git a/fs/test.ts b/fs/test.ts index dac0d350ddde..5cff8e17467a 100644 --- a/fs/test.ts +++ b/fs/test.ts @@ -3,7 +3,6 @@ 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 "./empty_dir_test.ts"; import "./ensure_dir_test.ts"; diff --git a/test.ts b/test.ts index 9760b0f234ff..08b3fd6b526b 100755 --- a/test.ts +++ b/test.ts @@ -2,12 +2,12 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import "./colors/test.ts"; import "./datetime/test.ts"; +import "./encoding/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"; From de9abb486520894aa2fcfab81b8473c919d86fdd Mon Sep 17 00:00:00 2001 From: LE GOFF Vincent Date: Mon, 8 Apr 2019 15:34:48 +0200 Subject: [PATCH 2/2] undo move --- encoding/test.ts | 2 -- {encoding => fs}/eol.ts | 0 {encoding => fs}/eol_test.ts | 0 fs/test.ts | 1 + test.ts | 1 - 5 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 encoding/test.ts rename {encoding => fs}/eol.ts (100%) rename {encoding => fs}/eol_test.ts (100%) diff --git a/encoding/test.ts b/encoding/test.ts deleted file mode 100644 index 16f6aece5cae..000000000000 --- a/encoding/test.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import "./eol_test.ts"; diff --git a/encoding/eol.ts b/fs/eol.ts similarity index 100% rename from encoding/eol.ts rename to fs/eol.ts diff --git a/encoding/eol_test.ts b/fs/eol_test.ts similarity index 100% rename from encoding/eol_test.ts rename to fs/eol_test.ts diff --git a/fs/test.ts b/fs/test.ts index 5cff8e17467a..cc9013eed72e 100644 --- a/fs/test.ts +++ b/fs/test.ts @@ -4,6 +4,7 @@ import "./walk_test.ts"; import "./globrex_test.ts"; import "./glob_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 08b3fd6b526b..652ffcaaccf7 100755 --- a/test.ts +++ b/test.ts @@ -2,7 +2,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import "./colors/test.ts"; import "./datetime/test.ts"; -import "./encoding/test.ts"; import "./examples/test.ts"; import "./flags/test.ts"; import "./fs/test.ts";