2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-11-24 08:15:58 +00:00
|
|
|
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";
|
|
|
|
|
2020-02-11 16:24:27 +00:00
|
|
|
Deno.test({
|
2023-11-23 06:59:59 +00:00
|
|
|
name: "detect() detects CRLF as the end-of-line character",
|
2022-08-24 01:21:57 +00:00
|
|
|
fn() {
|
2023-11-24 08:15:58 +00:00
|
|
|
assertEquals(detect(CRLFinput), CRLF);
|
2020-03-28 17:03:49 +00:00
|
|
|
},
|
2019-04-07 01:06:07 +00:00
|
|
|
});
|
2019-04-13 19:24:36 +00:00
|
|
|
|
2020-02-11 16:24:27 +00:00
|
|
|
Deno.test({
|
2023-11-23 06:59:59 +00:00
|
|
|
name: "detect() detects LF as the end-of-line character",
|
2022-08-24 01:21:57 +00:00
|
|
|
fn() {
|
2023-11-24 08:15:58 +00:00
|
|
|
assertEquals(detect(LFinput), LF);
|
2020-03-28 17:03:49 +00:00
|
|
|
},
|
2019-04-07 01:06:07 +00:00
|
|
|
});
|
2019-04-13 19:24:36 +00:00
|
|
|
|
2020-02-11 16:24:27 +00:00
|
|
|
Deno.test({
|
2023-11-23 06:59:59 +00:00
|
|
|
name: "detect() returns null for a string with no end-of-line character",
|
2022-08-24 01:21:57 +00:00
|
|
|
fn() {
|
2019-04-13 19:24:36 +00:00
|
|
|
assertEquals(detect(NoNLinput), null);
|
2020-03-28 17:03:49 +00:00
|
|
|
},
|
2019-04-07 01:06:07 +00:00
|
|
|
});
|
2019-04-13 19:24:36 +00:00
|
|
|
|
2020-02-11 16:24:27 +00:00
|
|
|
Deno.test({
|
2023-11-23 06:59:59 +00:00
|
|
|
name:
|
|
|
|
"detect() detects the most common end-of-line character in a mixed string",
|
2022-08-24 01:21:57 +00:00
|
|
|
fn() {
|
2023-11-24 08:15:58 +00:00
|
|
|
assertEquals(detect(Mixedinput), CRLF);
|
|
|
|
assertEquals(detect(Mixedinput2), CRLF);
|
2020-03-28 17:03:49 +00:00
|
|
|
},
|
2019-04-13 19:24:36 +00:00
|
|
|
});
|
|
|
|
|
2020-02-11 16:24:27 +00:00
|
|
|
Deno.test({
|
2023-11-23 06:59:59 +00:00
|
|
|
name: "format() converts the end-of-line character to the specified one",
|
2022-08-24 01:21:57 +00:00
|
|
|
fn() {
|
2023-11-24 08:15:58 +00:00
|
|
|
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);
|
2020-03-28 17:03:49 +00:00
|
|
|
},
|
2019-04-07 01:06:07 +00:00
|
|
|
});
|