std/fs/eol_test.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { CRLF, detect, format, LF } from "./eol.ts";
2019-04-07 01:06:07 +00:00
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";
Deno.test({
name: "detect() detects CRLF as the end-of-line character",
fn() {
assertEquals(detect(CRLFinput), CRLF);
},
2019-04-07 01:06:07 +00:00
});
2019-04-13 19:24:36 +00:00
Deno.test({
name: "detect() detects LF as the end-of-line character",
fn() {
assertEquals(detect(LFinput), LF);
},
2019-04-07 01:06:07 +00:00
});
2019-04-13 19:24:36 +00:00
Deno.test({
name: "detect() returns null for a string with no end-of-line character",
fn() {
2019-04-13 19:24:36 +00:00
assertEquals(detect(NoNLinput), null);
},
2019-04-07 01:06:07 +00:00
});
2019-04-13 19:24:36 +00:00
Deno.test({
name:
"detect() detects the most common end-of-line character in a mixed string",
fn() {
assertEquals(detect(Mixedinput), CRLF);
assertEquals(detect(Mixedinput2), CRLF);
},
2019-04-13 19:24:36 +00:00
});
Deno.test({
name: "format() converts the end-of-line character to the specified one",
fn() {
assertEquals(format(CRLFinput, LF), LFinput);
assertEquals(format(LFinput, LF), LFinput);
assertEquals(format(LFinput, CRLF), CRLFinput);
assertEquals(format(CRLFinput, CRLF), CRLFinput);
assertEquals(format(CRLFinput, CRLF), CRLFinput);
assertEquals(format(NoNLinput, CRLF), NoNLinput);
assertEquals(format(Mixedinput, CRLF), CRLFinput);
assertEquals(format(Mixedinput, LF), LFinput);
assertEquals(format(Mixedinput2, CRLF), CRLFinput);
assertEquals(format(Mixedinput2, LF), LFinput);
},
2019-04-07 01:06:07 +00:00
});