-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtest-end-of-line.js
More file actions
47 lines (43 loc) · 1.14 KB
/
test-end-of-line.js
File metadata and controls
47 lines (43 loc) · 1.14 KB
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
import { format } from "./run-prettier.js";
import visualizeEndOfLine from "./utils/visualize-end-of-line.js";
async function testEndOfLine(
source,
formatResult,
_filename,
formatOptions,
eol,
) {
if (!shouldSkipEolTest(source, formatResult.options)) {
const { eolVisualizedOutput: output } = await format(
source.replace(/\n/gu, eol),
formatOptions,
);
// Only if `endOfLine: "auto"` the result will be different
const expected =
formatOptions.endOfLine === "auto"
? visualizeEndOfLine(
// All `code` use `LF`, so the `eol` of result is always `LF`
formatResult.outputWithCursor.replace(/\n/gu, eol),
)
: formatResult.eolVisualizedOutput;
expect(output).toEqual(expected);
}
}
function shouldSkipEolTest(source, options) {
if (source.includes("\r")) {
return true;
}
const { requirePragma, rangeStart, rangeEnd } = options;
if (requirePragma) {
return true;
}
if (
typeof rangeStart === "number" &&
typeof rangeEnd === "number" &&
rangeStart >= rangeEnd
) {
return true;
}
return false;
}
export { testEndOfLine as run };