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 {
3434 /// token, or `nil` if it does not represent one.
3535 var rawIdentifier : String ? {
3636 let ( textWithoutBackticks, backticksRemoved) = _textWithoutBackticks
37- if backticksRemoved, textWithoutBackticks. contains ( where : \ . isWhitespace ) {
37+ if backticksRemoved, ! textWithoutBackticks. isValidSwiftIdentifier ( for : . memberAccess ) {
3838 return textWithoutBackticks
3939 }
4040
Original file line number Diff line number Diff line change @@ -256,6 +256,21 @@ struct TestDeclarationMacroTests {
256256 }
257257 }
258258
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+
259274 @Test ( " Warning diagnostics emitted on API misuse " ,
260275 arguments: [
261276 // return types
You can’t perform that action at this time.
0 commit comments