11import SwiftFormat
22@_spi ( Rules) @_spi ( Testing) import SwiftFormat
33import SwiftOperators
4- import SwiftParser
4+ @ _spi ( ExperimentalLanguageFeatures ) import SwiftParser
55import SwiftSyntax
66import XCTest
77@_spi ( Testing) import _SwiftFormatTestSupport
@@ -18,6 +18,8 @@ class PrettyPrintTestCase: DiagnosingTestCase {
1818 /// changes that insert or remove non-whitespace characters (like trailing commas).
1919 /// - findings: A list of `FindingSpec` values that describe the findings that are expected to
2020 /// be emitted. These are currently only checked if `whitespaceOnly` is true.
21+ /// - experimentalFeatures: The set of experimental features that should be enabled in the
22+ /// parser.
2123 /// - file: The file in which failure occurred. Defaults to the file name of the test case in
2224 /// which this function was called.
2325 /// - line: The line number on which failure occurred. Defaults to the line number on which this
@@ -29,6 +31,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
2931 configuration: Configuration = Configuration . forTesting,
3032 whitespaceOnly: Bool = false ,
3133 findings: [ FindingSpec ] = [ ] ,
34+ experimentalFeatures: Parser . ExperimentalFeatures = [ ] ,
3235 file: StaticString = #file,
3336 line: UInt = #line
3437 ) {
@@ -44,6 +47,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
4447 configuration: configuration,
4548 selection: markedInput. selection,
4649 whitespaceOnly: whitespaceOnly,
50+ experimentalFeatures: experimentalFeatures,
4751 findingConsumer: { emittedFindings. append ( $0) }
4852 )
4953 assertStringsEqualWithDiff (
@@ -76,6 +80,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
7680 configuration: configuration,
7781 selection: markedInput. selection,
7882 whitespaceOnly: whitespaceOnly,
83+ experimentalFeatures: experimentalFeatures,
7984 findingConsumer: { _ in } // Ignore findings during the idempotence check.
8085 )
8186 assertStringsEqualWithDiff (
@@ -95,18 +100,23 @@ class PrettyPrintTestCase: DiagnosingTestCase {
95100 /// - configuration: The formatter configuration.
96101 /// - whitespaceOnly: If true, the pretty printer should only apply whitespace changes and omit
97102 /// changes that insert or remove non-whitespace characters (like trailing commas).
103+ /// - experimentalFeatures: The set of experimental features that should be enabled in the
104+ /// parser.
98105 /// - findingConsumer: A function called for each finding that is emitted by the pretty printer.
99106 /// - Returns: The pretty-printed text, or nil if an error occurred and a test failure was logged.
100107 private func prettyPrintedSource(
101108 _ source: String ,
102109 configuration: Configuration ,
103110 selection: Selection ,
104111 whitespaceOnly: Bool ,
112+ experimentalFeatures: Parser . ExperimentalFeatures = [ ] ,
105113 findingConsumer: @escaping ( Finding ) -> Void
106114 ) -> ( String , Context ) {
107115 // Ignore folding errors for unrecognized operators so that we fallback to a reasonable default.
108116 let sourceFileSyntax =
109- OperatorTable . standardOperators. foldAll ( Parser . parse ( source: source) ) { _ in }
117+ OperatorTable . standardOperators. foldAll (
118+ Parser . parse ( source: source, experimentalFeatures: experimentalFeatures)
119+ ) { _ in }
110120 . as ( SourceFileSyntax . self) !
111121 let context = makeContext (
112122 sourceFileSyntax: sourceFileSyntax,
0 commit comments