1
1
import SwiftFormat
2
2
@_spi ( Rules) @_spi ( Testing) import SwiftFormat
3
3
import SwiftOperators
4
- import SwiftParser
4
+ @ _spi ( ExperimentalLanguageFeatures ) import SwiftParser
5
5
import SwiftSyntax
6
6
import XCTest
7
7
@_spi ( Testing) import _SwiftFormatTestSupport
@@ -18,6 +18,8 @@ class PrettyPrintTestCase: DiagnosingTestCase {
18
18
/// changes that insert or remove non-whitespace characters (like trailing commas).
19
19
/// - findings: A list of `FindingSpec` values that describe the findings that are expected to
20
20
/// 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.
21
23
/// - file: The file in which failure occurred. Defaults to the file name of the test case in
22
24
/// which this function was called.
23
25
/// - line: The line number on which failure occurred. Defaults to the line number on which this
@@ -29,6 +31,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
29
31
configuration: Configuration = Configuration . forTesting,
30
32
whitespaceOnly: Bool = false ,
31
33
findings: [ FindingSpec ] = [ ] ,
34
+ experimentalFeatures: Parser . ExperimentalFeatures = [ ] ,
32
35
file: StaticString = #file,
33
36
line: UInt = #line
34
37
) {
@@ -44,6 +47,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
44
47
configuration: configuration,
45
48
selection: markedInput. selection,
46
49
whitespaceOnly: whitespaceOnly,
50
+ experimentalFeatures: experimentalFeatures,
47
51
findingConsumer: { emittedFindings. append ( $0) }
48
52
)
49
53
assertStringsEqualWithDiff (
@@ -76,6 +80,7 @@ class PrettyPrintTestCase: DiagnosingTestCase {
76
80
configuration: configuration,
77
81
selection: markedInput. selection,
78
82
whitespaceOnly: whitespaceOnly,
83
+ experimentalFeatures: experimentalFeatures,
79
84
findingConsumer: { _ in } // Ignore findings during the idempotence check.
80
85
)
81
86
assertStringsEqualWithDiff (
@@ -95,18 +100,23 @@ class PrettyPrintTestCase: DiagnosingTestCase {
95
100
/// - configuration: The formatter configuration.
96
101
/// - whitespaceOnly: If true, the pretty printer should only apply whitespace changes and omit
97
102
/// 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.
98
105
/// - findingConsumer: A function called for each finding that is emitted by the pretty printer.
99
106
/// - Returns: The pretty-printed text, or nil if an error occurred and a test failure was logged.
100
107
private func prettyPrintedSource(
101
108
_ source: String ,
102
109
configuration: Configuration ,
103
110
selection: Selection ,
104
111
whitespaceOnly: Bool ,
112
+ experimentalFeatures: Parser . ExperimentalFeatures = [ ] ,
105
113
findingConsumer: @escaping ( Finding ) -> Void
106
114
) -> ( String , Context ) {
107
115
// Ignore folding errors for unrecognized operators so that we fallback to a reasonable default.
108
116
let sourceFileSyntax =
109
- OperatorTable . standardOperators. foldAll ( Parser . parse ( source: source) ) { _ in }
117
+ OperatorTable . standardOperators. foldAll (
118
+ parseForTesting ( source: source, experimentalFeatures: experimentalFeatures)
119
+ ) { _ in }
110
120
. as ( SourceFileSyntax . self) !
111
121
let context = makeContext (
112
122
sourceFileSyntax: sourceFileSyntax,
0 commit comments