@@ -20,7 +20,7 @@ class TestNSCache : XCTestCase {
2020 static var allTests : [ ( String , ( TestNSCache ) -> ( ) throws -> Void ) ] {
2121 return [
2222 ( " test_setWithUnmutableKeys " , test_setWithUnmutableKeys) ,
23- // FIXME: https://bugs.swift.org/browse/SR-7161 ("test_setWithMutableKeys", test_setWithMutableKeys),
23+ ( " test_setWithMutableKeys " , test_setWithMutableKeys) ,
2424 ( " test_costLimit " , test_costLimit) ,
2525 ( " test_countLimit " , test_countLimit) ,
2626 ( " test_hashableKey " , test_hashableKey) ,
@@ -72,9 +72,21 @@ class TestNSCache : XCTestCase {
7272 XCTAssertEqual ( cache. object ( forKey: key2) , value, " should be equal to \( value) when using second key " )
7373
7474 key1. append ( " 1 " )
75-
76- XCTAssertEqual ( cache. object ( forKey: key1) , value, " should be equal to \( value) when using first key " )
75+
76+ // Mutating the key probably changes the hash value, which often makes
77+ // the value inaccessible by sorting the key into a different bucket.
78+ // On the other hand, the bucket may remain the same by coincidence.
79+ // Therefore, `cache.object(forKey: key1)` may or may not be nil at
80+ // this point -- no useful check can be made.
81+ // The object can definitely not be reached via the original key,
82+ // though.
7783 XCTAssertNil ( cache. object ( forKey: key2) , " should be nil " )
84+
85+ // Restoring key1 to the original string will make the value
86+ // accessible again.
87+ key1. setString ( " key " )
88+ XCTAssertEqual ( cache. object ( forKey: key1) , value, " should be equal to \( value) when using first key " )
89+ XCTAssertEqual ( cache. object ( forKey: key2) , value, " should be equal to \( value) when using second key " )
7890 }
7991
8092 func test_costLimit( ) {
0 commit comments