@@ -18,6 +18,7 @@ final class Test_URIParser: Test_Runtime {
1818
1919 let testedVariants : [ URICoderConfiguration ] = [
2020 . formExplode, . formUnexplode, . simpleExplode, . simpleUnexplode, . formDataExplode, . formDataUnexplode,
21+ . deepObjectExplode,
2122 ]
2223
2324 func testParsing( ) throws {
@@ -29,7 +30,8 @@ final class Test_URIParser: Test_Runtime {
2930 simpleExplode: . custom( " " , value: [ " " : [ " " ] ] ) ,
3031 simpleUnexplode: . custom( " " , value: [ " " : [ " " ] ] ) ,
3132 formDataExplode: " empty= " ,
32- formDataUnexplode: " empty= "
33+ formDataUnexplode: " empty= " ,
34+ deepObjectExplode: " object%5Bempty%5D= "
3335 ) ,
3436 value: [ " empty " : [ " " ] ]
3537 ) ,
@@ -40,7 +42,8 @@ final class Test_URIParser: Test_Runtime {
4042 simpleExplode: . custom( " " , value: [ " " : [ " " ] ] ) ,
4143 simpleUnexplode: . custom( " " , value: [ " " : [ " " ] ] ) ,
4244 formDataExplode: " " ,
43- formDataUnexplode: " "
45+ formDataUnexplode: " " ,
46+ deepObjectExplode: " "
4447 ) ,
4548 value: [ : ]
4649 ) ,
@@ -51,7 +54,8 @@ final class Test_URIParser: Test_Runtime {
5154 simpleExplode: . custom( " fred " , value: [ " " : [ " fred " ] ] ) ,
5255 simpleUnexplode: . custom( " fred " , value: [ " " : [ " fred " ] ] ) ,
5356 formDataExplode: " who=fred " ,
54- formDataUnexplode: " who=fred "
57+ formDataUnexplode: " who=fred " ,
58+ deepObjectExplode: " object%5Bwho%5D=fred "
5559 ) ,
5660 value: [ " who " : [ " fred " ] ]
5761 ) ,
@@ -62,7 +66,8 @@ final class Test_URIParser: Test_Runtime {
6266 simpleExplode: . custom( " Hello%20World " , value: [ " " : [ " Hello World " ] ] ) ,
6367 simpleUnexplode: . custom( " Hello%20World " , value: [ " " : [ " Hello World " ] ] ) ,
6468 formDataExplode: " hello=Hello+World " ,
65- formDataUnexplode: " hello=Hello+World "
69+ formDataUnexplode: " hello=Hello+World " ,
70+ deepObjectExplode: " object%5Bhello%5D=Hello%20World "
6671 ) ,
6772 value: [ " hello " : [ " Hello World " ] ]
6873 ) ,
@@ -73,7 +78,11 @@ final class Test_URIParser: Test_Runtime {
7378 simpleExplode: . custom( " red,green,blue " , value: [ " " : [ " red " , " green " , " blue " ] ] ) ,
7479 simpleUnexplode: . custom( " red,green,blue " , value: [ " " : [ " red " , " green " , " blue " ] ] ) ,
7580 formDataExplode: " list=red&list=green&list=blue " ,
76- formDataUnexplode: " list=red,green,blue "
81+ formDataUnexplode: " list=red,green,blue " ,
82+ deepObjectExplode: . custom(
83+ " object%5Blist%5D=red&object%5Blist%5D=green&object%5Blist%5D=blue " ,
84+ expectedError: . malformedKeyValuePair( " list " )
85+ )
7786 ) ,
7887 value: [ " list " : [ " red " , " green " , " blue " ] ]
7988 ) ,
@@ -93,22 +102,37 @@ final class Test_URIParser: Test_Runtime {
93102 formDataUnexplode: . custom(
94103 " keys=comma,%2C,dot,.,semi,%3B " ,
95104 value: [ " keys " : [ " comma " , " , " , " dot " , " . " , " semi " , " ; " ] ]
96- )
105+ ) ,
106+ deepObjectExplode: " keys%5Bcomma%5D=%2C&keys%5Bdot%5D=.&keys%5Bsemi%5D=%3B "
97107 ) ,
98108 value: [ " semi " : [ " ; " ] , " dot " : [ " . " ] , " comma " : [ " , " ] ]
99109 ) ,
100110 ]
101111 for testCase in cases {
102112 func testVariant( _ variant: Case . Variant , _ input: Case . Variants . Input ) throws {
103113 var parser = URIParser ( configuration: variant. config, data: input. string [ ... ] )
104- let parsedNode = try parser. parseRoot ( )
105- XCTAssertEqual (
106- parsedNode,
107- input. valueOverride ?? testCase. value,
108- " Failed for config: \( variant. name) " ,
109- file: testCase. file,
110- line: testCase. line
111- )
114+ do {
115+ let parsedNode = try parser. parseRoot ( )
116+ XCTAssertEqual (
117+ parsedNode,
118+ input. valueOverride ?? testCase. value,
119+ " Failed for config: \( variant. name) " ,
120+ file: testCase. file,
121+ line: testCase. line
122+ )
123+ } catch {
124+ guard let expectedError = input. expectedError, let parsingError = error as? ParsingError else {
125+ XCTAssert ( false , " Unexpected error thrown: \( error) " , file: testCase. file, line: testCase. line)
126+ return
127+ }
128+ XCTAssertEqual (
129+ expectedError,
130+ parsingError,
131+ " Failed for config: \( variant. name) " ,
132+ file: testCase. file,
133+ line: testCase. line
134+ )
135+ }
112136 }
113137 let variants = testCase. variants
114138 try testVariant ( . formExplode, variants. formExplode)
@@ -117,6 +141,7 @@ final class Test_URIParser: Test_Runtime {
117141 try testVariant ( . simpleUnexplode, variants. simpleUnexplode)
118142 try testVariant ( . formDataExplode, variants. formDataExplode)
119143 try testVariant ( . formDataUnexplode, variants. formDataUnexplode)
144+ try testVariant ( . deepObjectExplode, variants. deepObjectExplode)
120145 }
121146 }
122147}
@@ -133,25 +158,32 @@ extension Test_URIParser {
133158 static let simpleUnexplode : Self = . init( name: " simpleUnexplode " , config: . simpleUnexplode)
134159 static let formDataExplode : Self = . init( name: " formDataExplode " , config: . formDataExplode)
135160 static let formDataUnexplode : Self = . init( name: " formDataUnexplode " , config: . formDataUnexplode)
161+ static let deepObjectExplode : Self = . init( name: " deepObjectExplode " , config: . deepObjectExplode)
136162 }
137163 struct Variants {
138164
139165 struct Input : ExpressibleByStringLiteral {
140166 var string : String
141167 var valueOverride : URIParsedNode ?
168+ var expectedError : ParsingError ?
142169
143- init ( string: String , valueOverride: URIParsedNode ? = nil ) {
170+ init ( string: String , valueOverride: URIParsedNode ? = nil , expectedError : ParsingError ? = nil ) {
144171 self . string = string
145172 self . valueOverride = valueOverride
173+ self . expectedError = expectedError
146174 }
147175
148176 static func custom( _ string: String , value: URIParsedNode ) -> Self {
149- . init( string: string, valueOverride: value)
177+ . init( string: string, valueOverride: value, expectedError: nil )
178+ }
179+ static func custom( _ string: String , expectedError: ParsingError ) -> Self {
180+ . init( string: string, valueOverride: nil , expectedError: expectedError)
150181 }
151182
152183 init ( stringLiteral value: String ) {
153184 self . string = value
154185 self . valueOverride = nil
186+ self . expectedError = nil
155187 }
156188 }
157189
@@ -161,6 +193,7 @@ extension Test_URIParser {
161193 var simpleUnexplode : Input
162194 var formDataExplode : Input
163195 var formDataUnexplode : Input
196+ var deepObjectExplode : Input
164197 }
165198 var variants : Variants
166199 var value : URIParsedNode
0 commit comments