1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00

EOL add mixed detection (denoland/deno_std#325)

Original: bb92c44c64
This commit is contained in:
Vincent LE GOFF 2019-04-13 21:24:36 +02:00 committed by Ryan Dahl
parent 236cedc7cb
commit 0c877a1283
4 changed files with 43 additions and 21 deletions

View file

@ -17,7 +17,7 @@ export function detect(content: string): EOL | null {
if (!d || d.length === 0) { if (!d || d.length === 0) {
return null; return null;
} }
const crlf = d.filter(x => x === EOL.CRLF); const crlf = d.filter((x: string) => x === EOL.CRLF);
if (crlf.length > 0) { if (crlf.length > 0) {
return EOL.CRLF; return EOL.CRLF;
} else { } else {

View file

@ -9,16 +9,38 @@ const Mixedinput2 = "deno\r\nis not\nnode";
const LFinput = "deno\nis not\nnode"; const LFinput = "deno\nis not\nnode";
const NoNLinput = "deno is not node"; const NoNLinput = "deno is not node";
test(function detectCRLF() { test({
name: "[EOL] Detect CR LF",
fn() {
assertEquals(detect(CRLFinput), EOL.CRLF); assertEquals(detect(CRLFinput), EOL.CRLF);
}
}); });
test(function detectLF() {
test({
name: "[EOL] Detect LF",
fn() {
assertEquals(detect(LFinput), EOL.LF); assertEquals(detect(LFinput), EOL.LF);
}
}); });
test(function detectNoNewLine() {
test({
name: "[EOL] Detect No New Line",
fn() {
assertEquals(detect(NoNLinput), null); assertEquals(detect(NoNLinput), null);
}
}); });
test(function testFormat() {
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(CRLFinput, EOL.LF), LFinput);
assertEquals(format(LFinput, EOL.LF), LFinput); assertEquals(format(LFinput, EOL.LF), LFinput);
assertEquals(format(LFinput, EOL.CRLF), CRLFinput); assertEquals(format(LFinput, EOL.CRLF), CRLFinput);
@ -29,4 +51,5 @@ test(function testFormat() {
assertEquals(format(Mixedinput, EOL.LF), LFinput); assertEquals(format(Mixedinput, EOL.LF), LFinput);
assertEquals(format(Mixedinput2, EOL.CRLF), CRLFinput); assertEquals(format(Mixedinput2, EOL.CRLF), CRLFinput);
assertEquals(format(Mixedinput2, EOL.LF), LFinput); assertEquals(format(Mixedinput2, EOL.LF), LFinput);
}
}); });

View file

@ -3,8 +3,8 @@ import "./path/test.ts";
import "./walk_test.ts"; import "./walk_test.ts";
import "./globrex_test.ts"; import "./globrex_test.ts";
import "./glob_test.ts"; import "./glob_test.ts";
import "./eol_test.ts";
import "./exists_test.ts"; import "./exists_test.ts";
import "./eol_test.ts";
import "./empty_dir_test.ts"; import "./empty_dir_test.ts";
import "./ensure_dir_test.ts"; import "./ensure_dir_test.ts";
import "./ensure_file_test.ts"; import "./ensure_file_test.ts";

View file

@ -4,10 +4,9 @@ import "./colors/test.ts";
import "./datetime/test.ts"; import "./datetime/test.ts";
import "./examples/test.ts"; import "./examples/test.ts";
import "./flags/test.ts"; import "./flags/test.ts";
import "./io/test.ts";
import "./fs/test.ts"; import "./fs/test.ts";
import "./io/test.ts";
import "./http/test.ts"; import "./http/test.ts";
import "./io/test.ts";
import "./log/test.ts"; import "./log/test.ts";
import "./media_types/test.ts"; import "./media_types/test.ts";
import "./multipart/test.ts"; import "./multipart/test.ts";