@@ -7,6 +7,7 @@ import consistentEndOfLine from "./utils/consistent-end-of-line.js";
77import createSnapshot from "./utils/create-snapshot.js" ;
88import visualizeEndOfLine from "./utils/visualize-end-of-line.js" ;
99import * as testAstCompare from "./test-ast-compare.js" ;
10+ import * as testEndOfLine from "./test-end-of-line.js" ;
1011import * as testSecondFormat from "./test-second-format.js" ;
1112import { shouldThrowOnFormat } from "./utilities.js" ;
1213import getPrettier from "./get-prettier.js" ;
@@ -129,24 +130,8 @@ async function runTest({
129130
130131 await testSecondFormat . run ( code , formatResult , filename , formatOptions ) ;
131132 await testAstCompare . run ( code , formatResult , filename , formatOptions ) ;
132-
133- if ( ! shouldSkipEolTest ( code , formatResult . options ) ) {
134- for ( const eol of [ "\r\n" , "\r" ] ) {
135- const { eolVisualizedOutput : output } = await format (
136- code . replace ( / \n / gu, eol ) ,
137- formatOptions ,
138- ) ;
139- // Only if `endOfLine: "auto"` the result will be different
140- const expected =
141- formatOptions . endOfLine === "auto"
142- ? visualizeEndOfLine (
143- // All `code` use `LF`, so the `eol` of result is always `LF`
144- formatResult . outputWithCursor . replace ( / \n / gu, eol ) ,
145- )
146- : formatResult . eolVisualizedOutput ;
147- expect ( output ) . toEqual ( expected ) ;
148- }
149- }
133+ await testEndOfLine . run ( code , formatResult , filename , formatOptions , "\r\n" ) ;
134+ await testEndOfLine . run ( code , formatResult , filename , formatOptions , "\r" ) ;
150135
151136 if ( code . charAt ( 0 ) !== BOM ) {
152137 const { eolVisualizedOutput : output } = await format (
@@ -164,23 +149,4 @@ async function runTest({
164149 }
165150}
166151
167- function shouldSkipEolTest ( code , options ) {
168- if ( code . includes ( "\r" ) ) {
169- return true ;
170- }
171- const { requirePragma, rangeStart, rangeEnd } = options ;
172- if ( requirePragma ) {
173- return true ;
174- }
175-
176- if (
177- typeof rangeStart === "number" &&
178- typeof rangeEnd === "number" &&
179- rangeStart >= rangeEnd
180- ) {
181- return true ;
182- }
183- return false ;
184- }
185-
186152export { runTest } ;
0 commit comments