@@ -32,11 +32,64 @@ class TestNotification : TestNotificationSuper {
32
32
func test_unconditionallyBridgeFromObjectiveC( ) {
33
33
expectEqual ( Notification ( name: Notification . Name ( " " ) ) , Notification . _unconditionallyBridgeFromObjectiveC ( nil ) )
34
34
}
35
+
36
+ func test_hashing( ) {
37
+ let o1 = NSObject ( )
38
+ let o2 = NSObject ( )
39
+ let values : [ Notification ] = [
40
+ /* 0 */ Notification ( name: . init( " a " ) , object: o1, userInfo: nil ) ,
41
+ /* 1 */ Notification ( name: . init( " b " ) , object: o1, userInfo: nil ) ,
42
+ /* 2 */ Notification ( name: . init( " a " ) , object: o2, userInfo: nil ) ,
43
+ /* 3 */ Notification ( name: . init( " a " ) , object: o1, userInfo: [ " Foo " : 1 ] ) ,
44
+ /* 4 */ Notification ( name: . init( " a " ) , object: o1, userInfo: [ " Foo " : 2 ] ) ,
45
+ /* 5 */ Notification ( name: . init( " a " ) , object: o1, userInfo: [ " Bar " : 1 ] ) ,
46
+ /* 6 */ Notification ( name: . init( " a " ) , object: o1, userInfo: [ " Foo " : 1 , " Bar " : 2 ] ) ,
47
+ ]
48
+
49
+ let hashException : Set < Int > = [ 3 , 4 ]
50
+
51
+ checkHashable (
52
+ values,
53
+ equalityOracle: { $0 == $1 } ,
54
+ hashEqualityOracle: {
55
+ // FIXME: Unfortunately cases 3 and 4 above currently hash the
56
+ // same way, even though they compare different.
57
+ $0 == $1 || ( hashException. contains ( $0) && hashException. contains ( $1) )
58
+ } )
59
+ }
35
60
}
36
61
37
62
38
63
#if !FOUNDATION_XCTEST
39
64
var NotificationTests = TestSuite ( " TestNotification " )
40
65
NotificationTests . test ( " test_unconditionallyBridgeFromObjectiveC " ) { TestNotification ( ) . test_unconditionallyBridgeFromObjectiveC ( ) }
66
+ NotificationTests . test ( " test_hashing " ) { TestNotification ( ) . test_hashing ( ) }
67
+
68
+ private struct NonHashableValueType : Equatable {
69
+ let value : Int
70
+ init ( _ value: Int ) {
71
+ self . value = value
72
+ }
73
+ }
74
+
75
+ NotificationTests . test ( " test_reflexivity_violation " )
76
+ . xfail (
77
+ . custom( { true } ,
78
+ reason: " <rdar://problem/49797185> Foundation.Notification's equality relation isn't reflexive " ) )
79
+ . code {
80
+ let name = Notification . Name ( " name " )
81
+ let a = NonHashableValueType ( 1 )
82
+ let b = NonHashableValueType ( 2 )
83
+ // Currently none of these values compare equal to themselves:
84
+ let values : [ Notification ] = [
85
+ Notification ( name: name, object: a, userInfo: nil ) ,
86
+ Notification ( name: name, object: b, userInfo: nil ) ,
87
+ Notification ( name: name, object: nil , userInfo: [ " foo " : a] ) ,
88
+ Notification ( name: name, object: nil , userInfo: [ " foo " : b] ) ,
89
+ ]
90
+ checkHashable ( values)
91
+ }
92
+
93
+
41
94
runAllTests ( )
42
95
#endif
0 commit comments