diff --git a/Sources/JSONAPISwiftGen/Swift Generators/Test Generators/TestFunctionName.swift b/Sources/JSONAPISwiftGen/Swift Generators/Test Generators/TestFunctionName.swift index 8e97eca..9cc8c2a 100644 --- a/Sources/JSONAPISwiftGen/Swift Generators/Test Generators/TestFunctionName.swift +++ b/Sources/JSONAPISwiftGen/Swift Generators/Test Generators/TestFunctionName.swift @@ -52,7 +52,7 @@ public struct TestFunctionName: Equatable, RawRepresentable { public var rawValue: String { return Self.testPrefix + nameApplying(pathComponentTransform: Self.functionEncodedName) - .replacingOccurrences(of: ".", with: "\(Self.periodReplacementCharacter)") + .replacingOccurrences(of: ".", with: "\(Self.moduleSeparatorPeriodReplacementCharacter)") } /// The fully qualified test function name is the name of the test @@ -83,7 +83,7 @@ public struct TestFunctionName: Equatable, RawRepresentable { let value = rawValue[rangeOfPrefix.upperBound...] - var components = value.split(separator: Self.periodReplacementCharacter) + var components = value.split(separator: Self.moduleSeparatorPeriodReplacementCharacter) guard components.count > 2 else { return nil @@ -130,6 +130,7 @@ public struct TestFunctionName: Equatable, RawRepresentable { .replacingOccurrences(of: "{", with: "\(Self.openBraceReplacementCharacter)") .replacingOccurrences(of: "}", with: "\(Self.closeBraceReplacementCharacter)") .replacingOccurrences(of: " ", with: "\(Self.spaceReplacementCharacter)") + .replacingOccurrences(of: ".", with: "\(Self.namePeriodReplacementCharacter)") } internal static func functionDecodedName(from string: String) -> String { @@ -137,14 +138,17 @@ public struct TestFunctionName: Equatable, RawRepresentable { .replacingOccurrences(of: "\(Self.openBraceReplacementCharacter)", with: "{") .replacingOccurrences(of: "\(Self.closeBraceReplacementCharacter)", with: "}") .replacingOccurrences(of: "\(Self.spaceReplacementCharacter)", with: " ") + .replacingOccurrences(of: "\(Self.namePeriodReplacementCharacter)", with: ".") } - /// For swift names, we remove braces, escape reserved words, and convert spaces to underscores. + /// For swift names, we remove braces, escape reserved words, and convert + /// spaces and periods to underscores. public static func swiftName(from string: String) -> String { let name = string .replacingOccurrences(of: "{", with: "") .replacingOccurrences(of: "}", with: "") .replacingOccurrences(of: " ", with: "_") + .replacingOccurrences(of: ".", with: "_") return Self.escapedKeyword(name) } @@ -160,7 +164,8 @@ public struct TestFunctionName: Equatable, RawRepresentable { private static var openBraceReplacementCharacter: Character = "➊" private static var closeBraceReplacementCharacter: Character = "➋" private static var spaceReplacementCharacter: Character = "➌" - private static var periodReplacementCharacter: Character = "➍" + private static var moduleSeparatorPeriodReplacementCharacter: Character = "➍" + private static var namePeriodReplacementCharacter: Character = "❺" // ➎ taken by `TestFunctionLocalContext.prefixSeparatorCharacter`. } diff --git a/Tests/JSONAPISwiftGenTests/TestFunctionNameTests.swift b/Tests/JSONAPISwiftGenTests/TestFunctionNameTests.swift index fb11533..ebb74b9 100644 --- a/Tests/JSONAPISwiftGenTests/TestFunctionNameTests.swift +++ b/Tests/JSONAPISwiftGenTests/TestFunctionNameTests.swift @@ -85,12 +85,35 @@ final class TestFunctionNameTests: XCTestCase { assertReflexiveRawValue( TestFunctionName( - path: .init(["go", "continue", "do", "accept"]), + path: .init(["go", "_", "continue", "do", "try", "accept"]), endpoint: .post, direction: .request, context: TestFunctionLocalContext(functionName: "_hello_world➎")! ) ) + + assertReflexiveRawValue( + TestFunctionName( + path: .init(["hello.world", "hi"]), + endpoint: .post, + direction: .request, + context: TestFunctionLocalContext(functionName: "_hello_world➎")! + ) + ) + } + + func test_periodInPath() { + let t1 = TestFunctionName( + path: .init(["hello.world", "hi"]), + endpoint: .post, + direction: .request, + context: TestFunctionLocalContext(functionName: "_hello_world➎")! + ) + XCTAssertEqual(t1.fullyQualifiedTestFunctionName, "hello_world.hi.POST.Request._hello_world➎") + XCTAssertEqual(t1.rawValue, "test__hello❺world➍hi➍POST➍Request➍_hello_world➎") + XCTAssertEqual(t1.testName, "_hello_world➎") + + XCTAssertEqual(TestFunctionName(rawValue: t1.rawValue)?.path, .init(["hello.world", "hi"])) } func test_reservedWordsInPath() {