@@ -55,13 +55,18 @@ final class SwiftFixItTests: XCTestCase {
55
55
56
56
private func _testAPI(
57
57
_ sourceFilePathsAndEdits: [ ( AbsolutePath , SourceFileEdit ) ] ,
58
- _ diagnostics: [ TestDiagnostic ]
58
+ _ diagnostics: [ TestDiagnostic ] ,
59
+ _ categories: Set < String > ,
59
60
) throws {
60
61
for (path, edit) in sourceFilePathsAndEdits {
61
62
try localFileSystem. writeFileContents ( path, string: edit. input)
62
63
}
63
64
64
- let swiftFixIt = try SwiftFixIt ( diagnostics: diagnostics, fileSystem: localFileSystem)
65
+ let swiftFixIt = try SwiftFixIt (
66
+ diagnostics: diagnostics,
67
+ categories: categories,
68
+ fileSystem: localFileSystem
69
+ )
65
70
try swiftFixIt. applyFixIts ( )
66
71
67
72
for (path, edit) in sourceFilePathsAndEdits {
@@ -75,6 +80,7 @@ final class SwiftFixItTests: XCTestCase {
75
80
76
81
// Cannot use variadic generics: crashes.
77
82
private func testAPI1File(
83
+ categories: Set < String > = [ ] ,
78
84
_ getTestCase: ( String ) -> TestCase < SourceFileEdit >
79
85
) throws {
80
86
try testWithTemporaryDirectory { fixturePath in
@@ -84,13 +90,15 @@ final class SwiftFixItTests: XCTestCase {
84
90
85
91
try self . _testAPI (
86
92
[ ( sourceFilePath, testCase. edits) ] ,
87
- testCase. diagnostics
93
+ testCase. diagnostics,
94
+ categories
88
95
)
89
96
}
90
97
}
91
98
92
99
private func testAPI2Files(
93
- _ getTestCase: ( String , String ) -> TestCase < ( SourceFileEdit , SourceFileEdit ) >
100
+ categories: Set < String > = [ ] ,
101
+ _ getTestCase: ( String , String ) -> TestCase < ( SourceFileEdit , SourceFileEdit ) > ,
94
102
) throws {
95
103
try testWithTemporaryDirectory { fixturePath in
96
104
let sourceFilePath1 = fixturePath. appending ( self . uniqueSwiftFileName ( ) )
@@ -100,7 +108,8 @@ final class SwiftFixItTests: XCTestCase {
100
108
101
109
try self . _testAPI (
102
110
[ ( sourceFilePath1, testCase. edits. 0 ) , ( sourceFilePath2, testCase. edits. 1 ) ] ,
103
- testCase. diagnostics
111
+ testCase. diagnostics,
112
+ categories
104
113
)
105
114
}
106
115
}
@@ -129,6 +138,85 @@ extension SwiftFixItTests {
129
138
}
130
139
}
131
140
141
+ func testCategoryFiltering( ) throws {
142
+ // Check that the fix-it gets ignored because category doesn't match
143
+ try self . testAPI1File ( categories: [ " Test " ] ) { ( filename: String ) in
144
+ . init(
145
+ edits: . init( input: " var x = 1 " , result: " var x = 1 " ) ,
146
+ diagnostics: [
147
+ TestDiagnostic (
148
+ text: " error " ,
149
+ level: . error,
150
+ location: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
151
+ fixIts: [
152
+ . init(
153
+ start: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
154
+ end: . init( filename: filename, line: 1 , column: 4 , offset: 0 ) ,
155
+ text: " let "
156
+ ) ,
157
+ ]
158
+ ) ,
159
+ ]
160
+ )
161
+ }
162
+
163
+ // Check that the fix-it gets ignored because category doesn't match
164
+ try self . testAPI1File ( categories: [ " Test " ] ) { ( filename: String ) in
165
+ . init(
166
+ edits: . init( input: " var x = 1 " , result: " var x = 1 " ) ,
167
+ diagnostics: [
168
+ TestDiagnostic (
169
+ text: " error " ,
170
+ level: . error,
171
+ location: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
172
+ category: " Other " ,
173
+ fixIts: [
174
+ . init(
175
+ start: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
176
+ end: . init( filename: filename, line: 1 , column: 4 , offset: 0 ) ,
177
+ text: " let "
178
+ ) ,
179
+ ]
180
+ ) ,
181
+ ]
182
+ )
183
+ }
184
+
185
+ try self . testAPI1File ( categories: [ " Other " , " Test " ] ) { ( filename: String ) in
186
+ . init(
187
+ edits: . init( input: " var x = 1 " , result: " let _ = 1 " ) ,
188
+ diagnostics: [
189
+ TestDiagnostic (
190
+ text: " error " ,
191
+ level: . error,
192
+ location: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
193
+ category: " Test " ,
194
+ fixIts: [
195
+ . init(
196
+ start: . init( filename: filename, line: 1 , column: 1 , offset: 0 ) ,
197
+ end: . init( filename: filename, line: 1 , column: 4 , offset: 0 ) ,
198
+ text: " let "
199
+ ) ,
200
+ ]
201
+ ) ,
202
+ TestDiagnostic (
203
+ text: " error " ,
204
+ level: . error,
205
+ location: . init( filename: filename, line: 1 , column: 4 , offset: 0 ) ,
206
+ category: " Other " ,
207
+ fixIts: [
208
+ . init(
209
+ start: . init( filename: filename, line: 1 , column: 5 , offset: 0 ) ,
210
+ end: . init( filename: filename, line: 1 , column: 6 , offset: 0 ) ,
211
+ text: " _ "
212
+ ) ,
213
+ ]
214
+ ) ,
215
+ ]
216
+ )
217
+ }
218
+ }
219
+
132
220
func testFixItIgnoredDiagnostic( ) throws {
133
221
try self . testAPI1File { ( filename: String ) in
134
222
. init(
0 commit comments