@@ -237,6 +237,9 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
237
237
return . skipChildren
238
238
}
239
239
240
+ let displayName = attributeData? . displayName ?? typeNames. last!
241
+ let typeNames = typeNames. map { backtickIfNeeded ( $0) . name }
242
+
240
243
let memberScanner = SyntacticSwiftTestingTestScanner (
241
244
snapshot: snapshot,
242
245
allTestsDisabled: attributeData? . isDisabled ?? false ,
@@ -256,7 +259,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
256
259
let testItem = AnnotatedTestItem (
257
260
testItem: TestItem (
258
261
id: ( parentTypeNames + typeNames) . joined ( separator: " / " ) ,
259
- label: attributeData ? . displayName ?? typeNames . last! ,
262
+ label: displayName,
260
263
disabled: ( attributeData? . isDisabled ?? false ) || allTestsDisabled,
261
264
style: TestStyle . swiftTesting,
262
265
location: Location ( uri: snapshot. uri, range: range) ,
@@ -305,15 +308,13 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
305
308
return visitTypeOrExtensionDecl ( node, typeNames: [ identifier. name] )
306
309
}
307
310
308
- /// If the given identifier requires backticks to be a valid decl identifier,
311
+ /// If the given name requires backticks to be a valid decl identifier,
309
312
/// applies backticks and returns `true` along with the new name. Otherwise
310
- /// returns `false` with the original name.
311
- func backtickIfNeeded( _ ident: Identifier ) -> ( backticked: Bool , name: String ) {
312
- let name = ident. name
313
- if name == " `` " {
314
- // Special case: `` stays as ``. Any other backticked name will have
315
- // been stripped by Identifier.
316
- return ( true , name)
313
+ /// returns `false` with the name.
314
+ func backtickIfNeeded( _ name: String ) -> ( backticked: Bool , name: String ) {
315
+ var name = name
316
+ if name. first == " ` " && name. last == " ` " {
317
+ name = String ( name. dropFirst ( ) . dropLast ( ) )
317
318
}
318
319
let needsBackticks = !name. isValidSwiftIdentifier ( for: . variableName)
319
320
return ( needsBackticks, needsBackticks ? " ` \( name) ` " : name)
@@ -335,16 +336,30 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
335
336
let parameters = node. signature. parameterClause. parameters. map { param in
336
337
let result =
337
338
if let identifier = param. firstName. identifier {
338
- backtickIfNeeded ( identifier) . name
339
+ backtickIfNeeded ( identifier. name ) . name
339
340
} else {
340
341
// Something like `_`, leave as-is.
341
342
param. firstName. text
342
343
}
343
344
return " \( result) : "
344
345
} . joined ( )
345
346
346
- let ( hasBackticks, baseName) = backtickIfNeeded ( identifier)
347
+ let ( hasBackticks, baseName) = backtickIfNeeded ( identifier. name )
347
348
let fullName = " \( baseName) ( \( parameters) ) "
349
+
350
+ // If we have a display name provided by the attribute, use it, otherwise
351
+ // we can infer the display name from a raw identifier if we have one.
352
+ //
353
+ // A raw identifier is considered an alternative way of spelling the display
354
+ // name, so e.g these have the same display name:
355
+ //
356
+ // ```
357
+ // @Test("foo bar") func foo() {}
358
+ // @Test func `foo bar`() {}
359
+ // ```
360
+ //
361
+ // as such it shouldn't include any parameters. If we just have a regular
362
+ // name then we use the full name as the display name.
348
363
let displayName = attributeData. displayName ?? ( hasBackticks ? identifier. name : fullName)
349
364
350
365
let range = snapshot. absolutePositionRange (
0 commit comments