@@ -105,27 +105,39 @@ class Test_TypeAssigner: Test_Core {
105105 }
106106
107107 func testContentSwiftName( ) throws {
108- let nameMaker = makeTranslator ( ) . typeAssigner. contentSwiftName
109- let cases : [ ( String , String ) ] = [
108+ let defensiveNameMaker = makeTranslator ( ) . typeAssigner. contentSwiftName
109+ let idiomaticNameMaker = makeTranslator ( namingStrategy: . idiomatic) . typeAssigner. contentSwiftName
110+ let cases : [ ( input: String , defensive: String , idiomatic: String ) ] = [
110111
111112 // Short names.
112- ( " application/json " , " json " ) , ( " application/x-www-form-urlencoded " , " urlEncodedForm " ) ,
113- ( " multipart/form-data " , " multipartForm " ) , ( " text/plain " , " plainText " ) , ( " */* " , " any " ) ,
114- ( " application/xml " , " xml " ) , ( " application/octet-stream " , " binary " ) , ( " text/html " , " html " ) ,
115- ( " application/yaml " , " yaml " ) , ( " text/csv " , " csv " ) , ( " image/png " , " png " ) , ( " application/pdf " , " pdf " ) ,
116- ( " image/jpeg " , " jpeg " ) ,
113+ ( " application/json " , " json " , " json " ) ,
114+ ( " application/x-www-form-urlencoded " , " urlEncodedForm " , " urlEncodedForm " ) ,
115+ ( " multipart/form-data " , " multipartForm " , " multipartForm " ) ,
116+ ( " text/plain " , " plainText " , " plainText " ) ,
117+ ( " */* " , " any " , " any " ) ,
118+ ( " application/xml " , " xml " , " xml " ) ,
119+ ( " application/octet-stream " , " binary " , " binary " ) ,
120+ ( " text/html " , " html " , " html " ) ,
121+ ( " application/yaml " , " yaml " , " yaml " ) ,
122+ ( " text/csv " , " csv " , " csv " ) ,
123+ ( " image/png " , " png " , " png " ) ,
124+ ( " application/pdf " , " pdf " , " pdf " ) ,
125+ ( " image/jpeg " , " jpeg " , " jpeg " ) ,
117126
118127 // Generic names.
119- ( " application/myformat+json " , " application_myformat_plus_json " ) , ( " foo/bar " , " foo_bar " ) ,
128+ ( " application/myformat+json " , " application_myformat_plus_json " , " applicationMyformatJson " ) ,
129+ ( " foo/bar " , " foo_bar " , " fooBar " ) ,
130+ ( " text/event-stream " , " text_event_hyphen_stream " , " textEventStream " ) ,
120131
121132 // Names with a parameter.
122- ( " application/foo " , " application_foo " ) ,
123- ( " application/foo; bar=baz; boo=foo " , " application_foo_bar_baz_boo_foo " ) ,
124- ( " application/foo; bar = baz " , " application_foo_bar_baz " ) ,
133+ ( " application/foo " , " application_foo " , " applicationFoo " ) ,
134+ ( " application/foo; bar=baz; boo=foo " , " application_foo_bar_baz_boo_foo " , " applicationFooBarBazBooFoo " ) ,
135+ ( " application/foo; bar = baz " , " application_foo_bar_baz " , " applicationFooBarBaz " ) ,
125136 ]
126- for (string, name ) in cases {
137+ for (string, defensiveName , idiomaticName ) in cases {
127138 let contentType = try XCTUnwrap ( ContentType ( string: string) )
128- XCTAssertEqual ( nameMaker ( contentType) , name, " Case \( string) failed " )
139+ XCTAssertEqual ( defensiveNameMaker ( contentType) , defensiveName, " Case \( string) failed for defensive strategy " )
140+ XCTAssertEqual ( idiomaticNameMaker ( contentType) , idiomaticName, " Case \( string) failed for idiomatic strategy " )
129141 }
130142 }
131143}
0 commit comments