-
Notifications
You must be signed in to change notification settings - Fork 92
/
addEmptyLineBefore.test.js
44 lines (33 loc) · 1.37 KB
/
addEmptyLineBefore.test.js
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
import postcss from "postcss";
import { addEmptyLineBefore } from "../addEmptyLineBefore";
describe("addEmptyLineBefore", () => {
it("adds single newline to the newline at the beginning", () => {
expect(run("a {}\n b{}", "\n")).toBe("a {}\n\n b{}");
});
it("adds single newline to newline at the beginning with CRLF", () => {
expect(run("a {}\r\n b{}", "\r\n")).toBe("a {}\r\n\r\n b{}");
});
it("adds single newline to newline at the end", () => {
expect(run("a {}\t\nb{}", "\n")).toBe("a {}\t\n\nb{}");
});
it("adds single newline to newline at the end with CRLF", () => {
expect(run("a {}\t\r\nb{}", "\r\n")).toBe("a {}\t\r\n\r\nb{}");
});
it("adds single newline to newline in the middle", () => {
expect(run("a {} \n\tb{}", "\n")).toBe("a {} \n\n\tb{}");
});
it("adds single newline to newline in the middle with CRLF", () => {
expect(run("a {} \r\n\tb{}", "\r\n")).toBe("a {} \r\n\r\n\tb{}");
});
it("adds two newlines if there aren't any existing newlines", () => {
expect(run("a {} b{}", "\n")).toBe("a {}\n\n b{}");
});
it("adds two newlines if there aren't any existing newlines with CRLF", () => {
expect(run("a {} b{}", "\r\n")).toBe("a {}\r\n\r\n b{}");
});
});
function run(css, lineEnding) {
const root = postcss.parse(css);
addEmptyLineBefore(root.nodes[1], lineEnding);
return root.toString();
}