Skip to content

Commit afb7a48

Browse files
committed
Test that the fixups are generated if display name is empty
No functional change: just adds new test cases for the change in swiftlang#1256 * Moved the tests previously added to `apiMisuseErrors` -> `apiMisuseErrorsIncludingFixIts`, and include the expected fixits It would probably be ok to leave them in `apiMisuseErrors` as well, but I think it would be kinda redundant since we also test the expected message along with the fixits already.
1 parent 75fde1d commit afb7a48

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

Tests/TestingMacrosTests/TestDeclarationMacroTests.swift

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ struct TestDeclarationMacroTests {
149149
"Attribute 'Test' cannot be applied to a function within structure 'S' because its conformance to 'Escapable' has been suppressed",
150150
"struct S: ~(Escapable) { @Test func f() {} }":
151151
"Attribute 'Test' cannot be applied to a function within structure 'S' because its conformance to 'Escapable' has been suppressed",
152-
153-
// empty display name string literal
154-
#"@Test("") func f() {}"#:
155-
"Attribute 'Test' specifies an empty display name for this function",
156-
##"@Test(#""#) func f() {}"##:
157-
"Attribute 'Test' specifies an empty display name for this function",
158-
#"@Suite("") struct S {}"#:
159-
"Attribute 'Suite' specifies an empty display name for this structure",
160152
]
161153
)
162154
func apiMisuseErrors(input: String, expectedMessage: String) throws {
@@ -241,6 +233,63 @@ struct TestDeclarationMacroTests {
241233
),
242234
]
243235
),
236+
237+
// empty display name string literal
238+
#"@Test("") func f() {}"#:
239+
(
240+
message: "Attribute 'Test' specifies an empty display name for this function",
241+
fixIts: [
242+
ExpectedFixIt(
243+
message: "Remove display name argument",
244+
changes: [
245+
.replace(oldSourceCode: #""""#, newSourceCode: "")
246+
]),
247+
ExpectedFixIt(
248+
message: "Add display name",
249+
changes: [
250+
.replace(
251+
oldSourceCode: #""""#,
252+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
253+
])
254+
]
255+
),
256+
##"@Test(#""#) func f() {}"##:
257+
(
258+
message: "Attribute 'Test' specifies an empty display name for this function",
259+
fixIts: [
260+
ExpectedFixIt(
261+
message: "Remove display name argument",
262+
changes: [
263+
.replace(oldSourceCode: ##"#""#"##, newSourceCode: "")
264+
]),
265+
ExpectedFixIt(
266+
message: "Add display name",
267+
changes: [
268+
.replace(
269+
oldSourceCode: ##"#""#"##,
270+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
271+
])
272+
]
273+
),
274+
#"@Suite("") struct S {}"#:
275+
(
276+
message:
277+
"Attribute 'Suite' specifies an empty display name for this structure",
278+
fixIts: [
279+
ExpectedFixIt(
280+
message: "Remove display name argument",
281+
changes: [
282+
.replace(oldSourceCode: #""""#, newSourceCode: "")
283+
]),
284+
ExpectedFixIt(
285+
message: "Add display name",
286+
changes: [
287+
.replace(
288+
oldSourceCode: #""""#,
289+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
290+
])
291+
]
292+
)
244293
]
245294
}
246295

0 commit comments

Comments
 (0)