-
Notifications
You must be signed in to change notification settings - Fork 16
/
fileformat_test.ts
99 lines (97 loc) · 2.18 KB
/
fileformat_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { assertEquals } from "@std/assert";
import { type FileFormat, findFileFormat, splitText } from "./fileformat.ts";
Deno.test("splitText", async (t) => {
await t.step("splits POSIX Text File properly (unix)", () => {
assertEquals(
splitText("Hello\nWorld\n", "unix"),
[
"Hello",
"World",
],
);
});
await t.step("splits POSIX Text File properly (dos)", () => {
assertEquals(
splitText("Hello\r\nWorld\r\n", "dos"),
[
"Hello",
"World",
],
);
});
await t.step("splits POSIX Text File properly (mac)", () => {
assertEquals(
splitText("Hello\rWorld\r", "mac"),
[
"Hello",
"World",
],
);
});
await t.step("splits invalid POSIX Text File properly (unix)", () => {
assertEquals(
splitText("Hello\nWorld", "unix"),
[
"Hello",
"World",
],
);
});
await t.step("splits invalid POSIX Text File properly (dos)", () => {
assertEquals(
splitText("Hello\r\nWorld", "dos"),
[
"Hello",
"World",
],
);
});
await t.step("splits invalid POSIX Text File properly (mac)", () => {
assertEquals(
splitText("Hello\rWorld", "mac"),
[
"Hello",
"World",
],
);
});
});
Deno.test("findFileFormat", async (t) => {
const ff: FileFormat[] = ["unix", "dos", "mac"];
await t.step("finds 'dos' properly", () => {
assertEquals(
findFileFormat("Hello\r\nWorld\r\n", ff),
"dos",
);
assertEquals(
findFileFormat("Hello\rWorld\r\n", ff),
"dos",
);
});
await t.step("finds 'unix' properly", () => {
assertEquals(
findFileFormat("Hello\nWorld\n", ff),
"unix",
);
assertEquals(
findFileFormat("Hello\r\nWorld\n", ff),
"unix",
);
assertEquals(
findFileFormat("Hello\rWorld\n", ff),
"unix",
);
});
await t.step("finds 'mac' properly", () => {
assertEquals(
findFileFormat("Hello\rWorld\r", ff),
"mac",
);
});
await t.step("uses the first fileformat as a fallback", () => {
assertEquals(
findFileFormat("Hello", ff),
"unix",
);
});
});