@@ -412,6 +412,99 @@ class TestCodable : XCTestCase {
412
412
expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitMass . kilograms) )
413
413
expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitLength . miles) )
414
414
}
415
+
416
+ // MARK: - URLComponents
417
+ lazy var urlComponentsValues : [ URLComponents ] = [
418
+ URLComponents ( ) ,
419
+
420
+ URLComponents ( string: " http://swift.org " ) !,
421
+ URLComponents ( string: " http://swift.org:80 " ) !,
422
+ URLComponents ( string: " https://www.mywebsite.org/api/v42/something.php#param1=hi¶m2=hello " ) !,
423
+ URLComponents ( string
: " ftp://johnny:[email protected] :4242/some/path " ) !
,
424
+
425
+ URLComponents ( url: URL ( string: " http://swift.org " ) !, resolvingAgainstBaseURL: false ) !,
426
+ URLComponents ( url: URL ( string: " http://swift.org:80 " ) !, resolvingAgainstBaseURL: false ) !,
427
+ URLComponents ( url: URL ( string: " https://www.mywebsite.org/api/v42/something.php#param1=hi¶m2=hello " ) !, resolvingAgainstBaseURL: false ) !,
428
+ URLComponents ( url
: URL ( string
: " ftp://johnny:[email protected] :4242/some/path " ) !
, resolvingAgainstBaseURL
: false ) !
,
429
+ URLComponents ( url: URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) , resolvingAgainstBaseURL: false ) !,
430
+ URLComponents ( url: URL ( fileURLWithPath: " / " ) , resolvingAgainstBaseURL: false ) !,
431
+ URLComponents ( url: URL ( string: " documentation " , relativeTo: URL ( string: " http://swift.org " ) !) !, resolvingAgainstBaseURL: false ) !,
432
+
433
+ URLComponents ( url: URL ( string: " http://swift.org " ) !, resolvingAgainstBaseURL: true ) !,
434
+ URLComponents ( url: URL ( string: " http://swift.org:80 " ) !, resolvingAgainstBaseURL: true ) !,
435
+ URLComponents ( url: URL ( string: " https://www.mywebsite.org/api/v42/something.php#param1=hi¶m2=hello " ) !, resolvingAgainstBaseURL: true ) !,
436
+ URLComponents ( url
: URL ( string
: " ftp://johnny:[email protected] :4242/some/path " ) !
, resolvingAgainstBaseURL
: true ) !
,
437
+ URLComponents ( url: URL ( fileURLWithPath: NSTemporaryDirectory ( ) ) , resolvingAgainstBaseURL: true ) !,
438
+ URLComponents ( url: URL ( fileURLWithPath: " / " ) , resolvingAgainstBaseURL: true ) !,
439
+ URLComponents ( url: URL ( string: " documentation " , relativeTo: URL ( string: " http://swift.org " ) !) !, resolvingAgainstBaseURL: true ) !,
440
+
441
+ {
442
+ var components = URLComponents ( )
443
+ components. scheme = " https "
444
+ return components
445
+ } ( ) ,
446
+
447
+ {
448
+ var components = URLComponents ( )
449
+ components. user = " johnny "
450
+ return components
451
+ } ( ) ,
452
+
453
+ {
454
+ var components = URLComponents ( )
455
+ components. password = " apples "
456
+ return components
457
+ } ( ) ,
458
+
459
+ {
460
+ var components = URLComponents ( )
461
+ components. host = " 0.0.0.0 "
462
+ return components
463
+ } ( ) ,
464
+
465
+ {
466
+ var components = URLComponents ( )
467
+ components. port = 8080
468
+ return components
469
+ } ( ) ,
470
+
471
+ {
472
+ var components = URLComponents ( )
473
+ components. path = " .. "
474
+ return components
475
+ } ( ) ,
476
+
477
+ {
478
+ var components = URLComponents ( )
479
+ components. query = " param1=hi¶m2=there "
480
+ return components
481
+ } ( ) ,
482
+
483
+ {
484
+ var components = URLComponents ( )
485
+ components. fragment = " anchor "
486
+ return components
487
+ } ( ) ,
488
+
489
+ {
490
+ var components = URLComponents ( )
491
+ components. scheme = " ftp "
492
+ components. user = " johnny "
493
+ components. password = " apples "
494
+ components. host = " 0.0.0.0 "
495
+ components. port = 4242
496
+ components. path = " /some/file "
497
+ components. query = " utf8=✅ "
498
+ components. fragment = " anchor "
499
+ return components
500
+ } ( )
501
+ ]
502
+
503
+ func test_URLComponents_JSON( ) {
504
+ for (components) in urlComponentsValues {
505
+ expectRoundTripEqualityThroughJSON ( for: components)
506
+ }
507
+ }
415
508
}
416
509
417
510
extension TestCodable {
@@ -434,6 +527,7 @@ extension TestCodable {
434
527
( " test_Calendar_JSON " , test_Calendar_JSON) ,
435
528
( " test_DateComponents_JSON " , test_DateComponents_JSON) ,
436
529
( " test_Measurement_JSON " , test_Measurement_JSON) ,
530
+ ( " test_URLComponents_JSON " , test_URLComponents_JSON) ,
437
531
]
438
532
}
439
533
}
0 commit comments