@@ -521,6 +521,7 @@ class TestURLComponents : XCTestCase {
521
521
( " test_port " , test_portSetter) ,
522
522
( " test_url " , test_url) ,
523
523
( " test_copy " , test_copy) ,
524
+ ( " test_hash " , test_hash) ,
524
525
( " test_createURLWithComponents " , test_createURLWithComponents) ,
525
526
( " test_path " , test_path) ,
526
527
( " test_percentEncodedPath " , test_percentEncodedPath) ,
@@ -615,7 +616,34 @@ class TestURLComponents : XCTestCase {
615
616
/* Assert that NSURLComponents.copy is actually a copy of NSURLComponents */
616
617
XCTAssertTrue ( copy. isEqual ( urlComponent) )
617
618
}
618
-
619
+
620
+ func test_hash( ) {
621
+ let c1 = URLComponents ( string: " https://www.swift.org/path/to/file.html?id=name " ) !
622
+ let c2 = URLComponents ( string: " https://www.swift.org/path/to/file.html?id=name " ) !
623
+
624
+ XCTAssertEqual ( c1, c2)
625
+ XCTAssertEqual ( c1. hashValue, c2. hashValue)
626
+
627
+ let strings : [ String ? ] = ( 0 ..< 20 ) . map { " s \( $0) " as String ? }
628
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . scheme, strings)
629
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . user, strings)
630
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . password, strings)
631
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . host, strings)
632
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . port, ( 0 ..< 20 ) . map { $0 as Int ? } )
633
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . path, strings. compactMap { $0 } )
634
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . query, strings)
635
+ checkHashableMutations_ValueType ( URLComponents ( ) , \URLComponents . fragment, strings)
636
+
637
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . scheme, strings)
638
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . user, strings)
639
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . password, strings)
640
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . host, strings)
641
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . port, ( 0 ..< 20 ) . map { $0 as NSNumber ? } )
642
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . path, strings)
643
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . query, strings)
644
+ checkHashableMutations_NSCopying ( NSURLComponents ( ) , \NSURLComponents . fragment, strings)
645
+ }
646
+
619
647
func test_createURLWithComponents( ) {
620
648
let urlComponents = NSURLComponents ( )
621
649
urlComponents. scheme = " https " ;
0 commit comments