@@ -11,6 +11,11 @@ import consistentEndOfLine from "./utils/consistent-end-of-line.js";
1111import createSnapshot from "./utils/create-snapshot.js" ;
1212import { stringifyOptionsForTitle } from "./utils/stringify-options-for-title.js" ;
1313import visualizeEndOfLine from "./utils/visualize-end-of-line.js" ;
14+ import {
15+ isAntlrMismatch ,
16+ isAstUnstable ,
17+ isUnstable ,
18+ } from "./failed-format-tests.js" ;
1419
1520const { __dirname } = createEsmUtils ( import . meta) ;
1621
@@ -21,32 +26,6 @@ const CURSOR_PLACEHOLDER = "<|>";
2126const RANGE_START_PLACEHOLDER = "<<<PRETTIER_RANGE_START>>>" ;
2227const RANGE_END_PLACEHOLDER = "<<<PRETTIER_RANGE_END>>>" ;
2328
24- // Here we add files that will not be the same when formatting a second time.
25- const unstableTests = new Map (
26- [ ] . map ( ( fixture ) => {
27- const [ file , isUnstable = ( ) => true ] = Array . isArray ( fixture )
28- ? fixture
29- : [ fixture ] ;
30- return [ path . join ( __dirname , "../format/" , file ) , isUnstable ] ;
31- } ) ,
32- ) ;
33-
34- // Here we add files that will not have the same AST after being formatted.
35- const unstableAstTests = new Map (
36- [
37- // `: =` and `= :` are syntactically the same as `:=` and `=:`, but the ast
38- // changes from `YulColonAndEqual` and `YulEqualAndColon` to `ColonEqual`
39- // and `EqualColon`, which is expected but the workaround to keep the test
40- // stable is too much, so we just put it in this list.
41- "AssemblyV0.4.26/Assembly.sol" ,
42- ] . map ( ( fixture ) => {
43- const [ file , isAstUnstable = ( ) => true ] = Array . isArray ( fixture )
44- ? fixture
45- : [ fixture ] ;
46- return [ path . join ( __dirname , "../format/" , file ) , isAstUnstable ] ;
47- } ) ,
48- ) ;
49-
5029const testsWithAstChanges = new Map (
5130 [
5231 "Parentheses/AddNoParentheses.sol" ,
@@ -71,60 +50,6 @@ const testsWithAstChanges = new Map(
7150 } ) ,
7251) ;
7352
74- const antlrMismatchTests = new Map (
75- [
76- // Better placement of comments in Slang.
77- "BasicIterator/BasicIterator.sol" ,
78- "Comments/Comments.sol" ,
79- "IndexOf/IndexOf.sol" ,
80- // Syntax for `pragma solidity 0.5.0 - 0.6.0;` not supported by ANTLR
81- "Pragma/Pragma.sol" ,
82- // ANTLR doesn't support assembly assignment operators separated by a space
83- // like `: =` or `= :`
84- "AssemblyV0.4.26/Assembly.sol" ,
85- // ANTLR doesn't support UntypedTupleMember with a storage location, which
86- // is valid Slang, but not in Solidity.
87- "AllSolidityFeaturesV0.4.26/AllSolidityFeatures.sol" ,
88- // TODO Review how ANTLR is formatting chained assignments
89- "Assignments/Assignments.sol" ,
90- ] . map ( ( fixture ) => {
91- const [ file , compareBytecode = ( ) => true ] = Array . isArray ( fixture )
92- ? fixture
93- : [ fixture ] ;
94- return [ path . join ( __dirname , "../format/" , file ) , compareBytecode ] ;
95- } ) ,
96- ) ;
97-
98- const isUnstable = ( filename , options ) => {
99- const testFunction = unstableTests . get ( filename ) ;
100-
101- if ( ! testFunction ) {
102- return false ;
103- }
104-
105- return testFunction ( options ) ;
106- } ;
107-
108- const isAstUnstable = ( filename , options ) => {
109- const testFunction = unstableAstTests . get ( filename ) ;
110-
111- if ( ! testFunction ) {
112- return false ;
113- }
114-
115- return testFunction ( options ) ;
116- } ;
117-
118- const isAntlrMismatch = ( filename , options ) => {
119- const testFunction = antlrMismatchTests . get ( filename ) ;
120-
121- if ( ! testFunction ) {
122- return false ;
123- }
124-
125- return testFunction ( options ) ;
126- } ;
127-
12853const shouldCompareBytecode = ( filename , options ) => {
12954 const testFunction = testsWithAstChanges . get ( filename ) ;
13055
0 commit comments