Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOL add mixed detection #325

Merged
merged 2 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fs/eol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 40 additions & 17 deletions fs/eol_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,47 @@ 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({
name: "[EOL] Detect CR LF",
fn() {
assertEquals(detect(CRLFinput), EOL.CRLF);
}
});
test(function detectLF() {
assertEquals(detect(LFinput), EOL.LF);

test({
name: "[EOL] Detect LF",
fn() {
assertEquals(detect(LFinput), EOL.LF);
}
});
test(function detectNoNewLine() {
assertEquals(detect(NoNLinput), null);

test({
name: "[EOL] Detect No New Line",
fn() {
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);

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);
}
});
2 changes: 1 addition & 1 deletion fs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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 "./eol_test.ts";
import "./empty_dir_test.ts";
import "./ensure_dir_test.ts";
import "./ensure_file_test.ts";
Expand Down
3 changes: 1 addition & 2 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import "./colors/test.ts";
import "./datetime/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";
Expand Down