@@ -45,7 +45,7 @@ public struct TestFunctionName: Equatable, RawRepresentable {
4545 /// To get the fully qualified name of the test, use `fullyQualifiedTestFunctionName`
4646 public var rawValue : String {
4747 return Self . testPrefix +
48- fullyQualifiedTestFunctionName
48+ nameApplying ( pathComponentTransform : Self . functionEncodedName )
4949 . replacingOccurrences ( of: " . " , with: " \( Self . periodReplacementCharacter) " )
5050 }
5151
@@ -54,11 +54,29 @@ public struct TestFunctionName: Equatable, RawRepresentable {
5454 /// callable whereas the `rawValue` is the name of the test function
5555 /// that will call this callable.
5656 public var fullyQualifiedTestFunctionName : String {
57+ return nameApplying ( pathComponentTransform: Self . swiftName)
58+ }
59+
60+ /// Will take a guess at what response status code is being tested, if applicable.
61+ /// The guess is determined using a known test name pattern of the status
62+ /// code being appending to the end of the test name after double underscores.
63+ public var testStatusCodeGuess : OpenAPI . Response . StatusCode ? {
64+ let components = testName. components ( separatedBy: " __ " )
65+
66+ guard components. count > 1 else { return nil }
67+
68+ return components. last. flatMap ( OpenAPI . Response. StatusCode. init ( rawValue: ) )
69+ }
70+
71+ /// This function facilitates a split between the `rawValue` and `fullyQualifiedTestFunctionName`
72+ /// because the former retains all path information with its `pathComponentTransform` whereas the
73+ /// latter is lossy with respect to some path component transformations.
74+ internal func nameApplying( pathComponentTransform: ( String ) -> String ) -> String {
5775 let components = path. components
58- + [ endpoint. rawValue, direction. rawValue]
76+ + [ endpoint. rawValue, direction. rawValue. capitalized ]
5977
6078 return components
61- . map ( Self . swiftTypeName )
79+ . map ( pathComponentTransform )
6280 . joined ( separator: " . " )
6381 + " . \( testName) "
6482 }
@@ -76,9 +94,9 @@ public struct TestFunctionName: Equatable, RawRepresentable {
7694 return nil
7795 }
7896
79- self . testName = String ( components. removeLast ( ) )
97+ self . testName = Self . functionDecodedName ( from : String ( components. removeLast ( ) ) )
8098
81- guard let direction = HttpDirection ( rawValue: String ( components. removeLast ( ) ) ) else {
99+ guard let direction = HttpDirection ( rawValue: String ( components. removeLast ( ) ) . lowercased ( ) ) else {
82100 return nil
83101 }
84102
@@ -90,7 +108,7 @@ public struct TestFunctionName: Equatable, RawRepresentable {
90108
91109 self . endpoint = endpoint
92110
93- self . path = OpenAPI . Path ( components. map ( String . init) )
111+ self . path = OpenAPI . Path ( components. map ( String . init) . map ( Self . functionDecodedName ) )
94112 }
95113
96114 public init (
@@ -105,14 +123,31 @@ public struct TestFunctionName: Equatable, RawRepresentable {
105123 self . testName = testName
106124 }
107125
108- internal static func swiftTypeName( from string: String ) -> String {
126+ /// For function name encoding we hold onto information like where there are
127+ /// spaces or braces.
128+ internal static func functionEncodedName( from string: String ) -> String {
109129 return string
110130 . replacingOccurrences ( of: " { " , with: " \( Self . openBraceReplacementCharacter) " )
111131 . replacingOccurrences ( of: " } " , with: " \( Self . closeBraceReplacementCharacter) " )
112132 . replacingOccurrences ( of: " " , with: " \( Self . spaceReplacementCharacter) " )
113133 }
114134
115- private static var testPrefix = " test__ "
135+ internal static func functionDecodedName( from string: String ) -> String {
136+ return string
137+ . replacingOccurrences ( of: " \( Self . openBraceReplacementCharacter) " , with: " { " )
138+ . replacingOccurrences ( of: " \( Self . closeBraceReplacementCharacter) " , with: " } " )
139+ . replacingOccurrences ( of: " \( Self . spaceReplacementCharacter) " , with: " " )
140+ }
141+
142+ /// For swift names, we remove braces and convert spaces to underscores.
143+ internal static func swiftName( from string: String ) -> String {
144+ return string
145+ . replacingOccurrences ( of: " { " , with: " " )
146+ . replacingOccurrences ( of: " } " , with: " " )
147+ . replacingOccurrences ( of: " " , with: " _ " )
148+ }
149+
150+ public static var testPrefix = " test__ "
116151 private static var openBraceReplacementCharacter : Character = " ➊ "
117152 private static var closeBraceReplacementCharacter : Character = " ➋ "
118153 private static var spaceReplacementCharacter : Character = " ➌ "
0 commit comments