File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Sources/TestingMacros/Support/Additions Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ extension TokenSyntax {
34
34
/// token, or `nil` if it does not represent one.
35
35
var rawIdentifier : String ? {
36
36
let ( textWithoutBackticks, backticksRemoved) = _textWithoutBackticks
37
- if backticksRemoved, textWithoutBackticks. contains ( where : \ . isWhitespace ) {
37
+ if backticksRemoved, ! textWithoutBackticks. isValidSwiftIdentifier ( for : . memberAccess ) {
38
38
return textWithoutBackticks
39
39
}
40
40
Original file line number Diff line number Diff line change @@ -256,6 +256,21 @@ struct TestDeclarationMacroTests {
256
256
}
257
257
}
258
258
259
+ @Test ( " Raw identifier is detected " )
260
+ func rawIdentifier( ) {
261
+ #expect( TokenSyntax . identifier ( " `hello` " ) . rawIdentifier == nil )
262
+ #expect( TokenSyntax . identifier ( " `helloworld` " ) . rawIdentifier == nil )
263
+ #expect( TokenSyntax . identifier ( " `hélloworld` " ) . rawIdentifier == nil )
264
+ #expect( TokenSyntax . identifier ( " `hello_world` " ) . rawIdentifier == nil )
265
+ #expect( TokenSyntax . identifier ( " `hello world` " ) . rawIdentifier != nil )
266
+ #expect( TokenSyntax . identifier ( " `hello/world` " ) . rawIdentifier != nil )
267
+ #expect( TokenSyntax . identifier ( " `hello \t world` " ) . rawIdentifier != nil )
268
+
269
+ #expect( TokenSyntax . identifier ( " `class` " ) . rawIdentifier == nil )
270
+ #expect( TokenSyntax . identifier ( " `struct` " ) . rawIdentifier == nil )
271
+ #expect( TokenSyntax . identifier ( " `class struct` " ) . rawIdentifier != nil )
272
+ }
273
+
259
274
@Test ( " Warning diagnostics emitted on API misuse " ,
260
275
arguments: [
261
276
// return types
You can’t perform that action at this time.
0 commit comments