2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-04-06 21:06:07 -04:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2020-09-27 06:22:32 -04:00
|
|
|
import { detect, EOL, format } from "./eol.ts";
|
2019-04-06 21:06:07 -04: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 11:24:27 -05:00
|
|
|
Deno.test({
|
2019-04-13 15:24:36 -04:00
|
|
|
name: "[EOL] Detect CR LF",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-04-13 15:24:36 -04:00
|
|
|
assertEquals(detect(CRLFinput), EOL.CRLF);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-04-06 21:06:07 -04:00
|
|
|
});
|
2019-04-13 15:24:36 -04:00
|
|
|
|
2020-02-11 11:24:27 -05:00
|
|
|
Deno.test({
|
2019-04-13 15:24:36 -04:00
|
|
|
name: "[EOL] Detect LF",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-04-13 15:24:36 -04:00
|
|
|
assertEquals(detect(LFinput), EOL.LF);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-04-06 21:06:07 -04:00
|
|
|
});
|
2019-04-13 15:24:36 -04:00
|
|
|
|
2020-02-11 11:24:27 -05:00
|
|
|
Deno.test({
|
2019-04-13 15:24:36 -04:00
|
|
|
name: "[EOL] Detect No New Line",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-04-13 15:24:36 -04:00
|
|
|
assertEquals(detect(NoNLinput), null);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-04-06 21:06:07 -04:00
|
|
|
});
|
2019-04-13 15:24:36 -04:00
|
|
|
|
2020-02-11 11:24:27 -05:00
|
|
|
Deno.test({
|
2019-04-13 15:24:36 -04:00
|
|
|
name: "[EOL] Detect Mixed",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-04-13 15:24:36 -04:00
|
|
|
assertEquals(detect(Mixedinput), EOL.CRLF);
|
|
|
|
assertEquals(detect(Mixedinput2), EOL.CRLF);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-04-13 15:24:36 -04:00
|
|
|
});
|
|
|
|
|
2020-02-11 11:24:27 -05:00
|
|
|
Deno.test({
|
2019-04-13 15:24:36 -04:00
|
|
|
name: "[EOL] Format",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-04-13 15:24:36 -04:00
|
|
|
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);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-04-06 21:06:07 -04:00
|
|
|
});
|