File tree 2 files changed +53
-0
lines changed 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ import Foundation
14
+
15
+ public struct Identifier {
16
+ public let name : String
17
+
18
+ public init ( _ token: TokenSyntax ) {
19
+ self . name = sanitizing ( token. text)
20
+ }
21
+ }
22
+
23
+ private func sanitizing( _ name: String ) -> String {
24
+ guard name. contains ( " ` " ) else {
25
+ return name
26
+ }
27
+
28
+ return name. trimmingCharacters ( in: CharacterSet ( charactersIn: " ` " ) )
29
+ }
Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ import SwiftSyntax
14
+ import XCTest
15
+
16
+ class IdentifierTests : XCTestCase {
17
+ public func testInit( ) {
18
+ let basicToken = TokenSyntax ( stringLiteral: " sometoken " )
19
+ XCTAssertEqual ( Identifier ( basicToken) . name, " sometoken " )
20
+
21
+ let backtickedToken = TokenSyntax ( stringLiteral: " `backtickedtoken` " )
22
+ XCTAssertEqual ( Identifier ( backtickedToken) . name, " backtickedtoken " )
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments