Fix range tests with TEST_CRLF and endOfLine option (#8821)
This commit is contained in:
1 parent
6793811da2
commit
0a2ec1b4a2
6 files changed
+366
-1
No files matched your search
@@ -0,0 +1,312 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`cursor-1.js - {"endOfLine":"auto"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "auto"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
(function(){return <|>15})()<LF>
|
||||
|
||||
=====================================output=====================================
|
||||
** The EOL of output might not real when \`TEST_CRLF\` **
|
||||
(function () {<LF>
|
||||
return <|>15;<LF>
|
||||
})();<LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`cursor-1.js - {"endOfLine":"cr"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "cr"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
(function(){return <|>15})()<LF>
|
||||
|
||||
=====================================output=====================================
|
||||
(function () {<CR>
|
||||
return <|>15;<CR>
|
||||
})();<CR>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`cursor-1.js - {"endOfLine":"crlf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "crlf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
(function(){return <|>15})()<LF>
|
||||
|
||||
=====================================output=====================================
|
||||
(function () {<CRLF>
|
||||
return <|>15;<CRLF>
|
||||
})();<CRLF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`cursor-1.js - {"endOfLine":"lf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "lf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
(function(){return <|>15})()<LF>
|
||||
|
||||
=====================================output=====================================
|
||||
(function () {<LF>
|
||||
return <|>15;<LF>
|
||||
})();<LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-1.js - {"endOfLine":"auto"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "auto"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
> 3 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 4 | b( ) {}<LF>
|
||||
| ^^^^^^^^^^^<LF>
|
||||
5 | }<LF>
|
||||
6 | <LF>
|
||||
7 | let x<LF>
|
||||
8 |
|
||||
=====================================output=====================================
|
||||
** The EOL of output might not real when \`TEST_CRLF\` **
|
||||
<LF>
|
||||
<LF>
|
||||
class a {<LF>
|
||||
b() {}<LF>
|
||||
}<LF>
|
||||
<LF>
|
||||
let x<LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-1.js - {"endOfLine":"cr"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "cr"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
> 3 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 4 | b( ) {}<LF>
|
||||
| ^^^^^^^^^^^<LF>
|
||||
5 | }<LF>
|
||||
6 | <LF>
|
||||
7 | let x<LF>
|
||||
8 |
|
||||
=====================================output=====================================
|
||||
<CR>
|
||||
<CR>
|
||||
class a {<CR>
|
||||
b() {}<CR>
|
||||
}<CR>
|
||||
<CR>
|
||||
let x<CR>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-1.js - {"endOfLine":"crlf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "crlf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
> 3 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 4 | b( ) {}<LF>
|
||||
| ^^^^^^^^^^^<LF>
|
||||
5 | }<LF>
|
||||
6 | <LF>
|
||||
7 | let x<LF>
|
||||
8 |
|
||||
=====================================output=====================================
|
||||
<CRLF>
|
||||
<CRLF>
|
||||
class a {<CRLF>
|
||||
b() {}<CRLF>
|
||||
}<CRLF>
|
||||
<CRLF>
|
||||
let x<CRLF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-1.js - {"endOfLine":"lf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "lf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
> 3 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 4 | b( ) {}<LF>
|
||||
| ^^^^^^^^^^^<LF>
|
||||
5 | }<LF>
|
||||
6 | <LF>
|
||||
7 | let x<LF>
|
||||
8 |
|
||||
=====================================output=====================================
|
||||
<LF>
|
||||
<LF>
|
||||
class a {<LF>
|
||||
b() {}<LF>
|
||||
}<LF>
|
||||
<LF>
|
||||
let x<LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-and-cursor-1.js - {"endOfLine":"auto"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "auto"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
3 | <LF>
|
||||
> 4 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 5 | b( <|> ) {}<LF>
|
||||
| ^^^^^^^^^^^^^^<LF>
|
||||
6 | }<LF>
|
||||
7 | <LF>
|
||||
8 | let x <LF>
|
||||
9 |
|
||||
=====================================output=====================================
|
||||
** The EOL of output might not real when \`TEST_CRLF\` **
|
||||
<LF>
|
||||
<LF>
|
||||
<LF>
|
||||
class a {<LF>
|
||||
b(<|>) {}<LF>
|
||||
}<LF>
|
||||
<LF>
|
||||
let x <LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-and-cursor-1.js - {"endOfLine":"cr"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "cr"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
3 | <LF>
|
||||
> 4 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 5 | b( <|> ) {}<LF>
|
||||
| ^^^^^^^^^^^^^^<LF>
|
||||
6 | }<LF>
|
||||
7 | <LF>
|
||||
8 | let x <LF>
|
||||
9 |
|
||||
=====================================output=====================================
|
||||
<CR>
|
||||
<CR>
|
||||
<CR>
|
||||
class a {<CR>
|
||||
b(<|>) {}<CR>
|
||||
}<CR>
|
||||
<CR>
|
||||
let x <CR>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-and-cursor-1.js - {"endOfLine":"crlf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "crlf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
3 | <LF>
|
||||
> 4 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 5 | b( <|> ) {}<LF>
|
||||
| ^^^^^^^^^^^^^^<LF>
|
||||
6 | }<LF>
|
||||
7 | <LF>
|
||||
8 | let x <LF>
|
||||
9 |
|
||||
=====================================output=====================================
|
||||
<CRLF>
|
||||
<CRLF>
|
||||
<CRLF>
|
||||
class a {<CRLF>
|
||||
b(<|>) {}<CRLF>
|
||||
}<CRLF>
|
||||
<CRLF>
|
||||
let x <CRLF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`range-and-cursor-1.js - {"endOfLine":"lf"} format 1`] = `
|
||||
====================================options=====================================
|
||||
endOfLine: "lf"
|
||||
parsers: ["babel"]
|
||||
printWidth: 80
|
||||
| | printWidth
|
||||
=====================================input======================================
|
||||
1 | <LF>
|
||||
2 | <LF>
|
||||
3 | <LF>
|
||||
> 4 | class a {<LF>
|
||||
| ^^^^<LF>
|
||||
> 5 | b( <|> ) {}<LF>
|
||||
| ^^^^^^^^^^^^^^<LF>
|
||||
6 | }<LF>
|
||||
7 | <LF>
|
||||
8 | let x <LF>
|
||||
9 |
|
||||
=====================================output=====================================
|
||||
<LF>
|
||||
<LF>
|
||||
<LF>
|
||||
class a {<LF>
|
||||
b(<|>) {}<LF>
|
||||
}<LF>
|
||||
<LF>
|
||||
let x <LF>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1 @@
|
||||
(function(){return <|>15})()
|
||||
@@ -0,0 +1,4 @@
|
||||
run_spec(__dirname, ["babel"], { endOfLine: "lf" });
|
||||
run_spec(__dirname, ["babel"], { endOfLine: "crlf" });
|
||||
run_spec(__dirname, ["babel"], { endOfLine: "cr" });
|
||||
run_spec(__dirname, ["babel"], { endOfLine: "auto" });
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
class <<<PRETTIER_RANGE_START>>> a {
|
||||
b( ) {}<<<PRETTIER_RANGE_END>>>
|
||||
}
|
||||
|
||||
let x
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
|
||||
class <<<PRETTIER_RANGE_START>>> a {
|
||||
b( <|> ) {}<<<PRETTIER_RANGE_END>>>
|
||||
}
|
||||
|
||||
let x
|
||||
@@ -179,23 +179,56 @@ global.run_spec = (fixtures, parsers, options) => {
|
||||
.replace(RANGE_END_PLACEHOLDER, "")
|
||||
: source;
|
||||
let codeOffset = 0;
|
||||
let resultForSnapshot = formattedWithCursor;
|
||||
|
||||
if (
|
||||
typeof baseOptions.rangeStart === "number" ||
|
||||
typeof baseOptions.rangeEnd === "number"
|
||||
) {
|
||||
if (TEST_CRLF && hasEndOfLine) {
|
||||
codeForSnapshot = codeForSnapshot.replace(/\n/g, "\r\n");
|
||||
}
|
||||
codeForSnapshot = visualizeRange(codeForSnapshot, baseOptions);
|
||||
codeOffset = codeForSnapshot.match(/^>?\s+1 \| /)[0].length;
|
||||
}
|
||||
|
||||
// When `TEST_CRLF` and `endOfLine: "auto"`, the eol is always `\r\n`,
|
||||
// Replace it with guess result from original input
|
||||
let resultNote = "";
|
||||
if (mainOptions.endOfLine === "auto") {
|
||||
const {
|
||||
guessEndOfLine,
|
||||
convertEndOfLineToChars,
|
||||
} = require("../src/common/end-of-line");
|
||||
const originalAutoResult = convertEndOfLineToChars(
|
||||
guessEndOfLine(code)
|
||||
);
|
||||
if (originalAutoResult !== "\r\n") {
|
||||
resultNote +=
|
||||
"** The EOL of output might not real when `TEST_CRLF` **";
|
||||
|
||||
if (TEST_CRLF) {
|
||||
resultForSnapshot = resultForSnapshot.replace(
|
||||
/\r\n?/g,
|
||||
originalAutoResult
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasEndOfLine) {
|
||||
codeForSnapshot = visualizeEndOfLine(codeForSnapshot);
|
||||
resultForSnapshot = visualizeEndOfLine(resultForSnapshot);
|
||||
}
|
||||
|
||||
if (resultNote) {
|
||||
resultForSnapshot = `${resultNote}\n${resultForSnapshot}`;
|
||||
}
|
||||
|
||||
expect(
|
||||
createSnapshot(
|
||||
codeForSnapshot,
|
||||
hasEndOfLine ? visualizedOutput : formattedWithCursor,
|
||||
resultForSnapshot,
|
||||
composeOptionsForSnapshot(baseOptions, parsers),
|
||||
{ codeOffset }
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user