@@ -95,6 +95,7 @@ fn dictionary_clone() {
95
95
"foo" : 0 ,
96
96
"bar" : subdictionary. clone( )
97
97
} ;
98
+
98
99
#[ allow( clippy:: redundant_clone) ]
99
100
let clone = dictionary. clone ( ) ;
100
101
Dictionary :: from_variant ( & clone. get ( "bar" ) . unwrap ( ) ) . insert ( "final" , 4 ) ;
@@ -103,12 +104,33 @@ fn dictionary_clone() {
103
104
104
105
#[ itest]
105
106
fn dictionary_hash ( ) {
106
- let dictionary = dict ! {
107
+ use godot:: builtin:: Vector2i ;
108
+
109
+ let a = dict ! {
107
110
"foo" : 0 ,
108
111
"bar" : true ,
109
- "baz" : "foobar"
112
+ ( Vector2i :: new( 4 , -1 ) ) : "foobar" ,
113
+ } ;
114
+ let b = dict ! {
115
+ "foo" : 0 ,
116
+ "bar" : true ,
117
+ ( Vector2i :: new( 4 , -1 ) ) : "foobar" // No comma to test macro.
110
118
} ;
111
- dictionary. hash ( ) ;
119
+ let c = dict ! {
120
+ "foo" : 0 ,
121
+ ( Vector2i :: new( 4 , -1 ) ) : "foobar" ,
122
+ "bar" : true ,
123
+ } ;
124
+
125
+ assert_eq ! ( a. hash( ) , b. hash( ) , "equal dictionaries have same hash" ) ;
126
+ assert_ne ! (
127
+ a. hash( ) ,
128
+ c. hash( ) ,
129
+ "dictionaries with reordered content have different hash"
130
+ ) ;
131
+
132
+ // NaNs are not equal (since Godot 4.2) but share same hash.
133
+ assert_eq ! ( dict! { 772 : f32 :: NAN } . hash( ) , dict! { 772 : f32 :: NAN } . hash( ) ) ;
112
134
}
113
135
114
136
#[ itest]
@@ -328,8 +350,13 @@ fn dictionary_keys_values() {
328
350
#[ itest]
329
351
fn dictionary_equal ( ) {
330
352
assert_eq ! ( dict! { "foo" : "bar" } , dict! { "foo" : "bar" } ) ;
331
- assert_eq ! ( dict! { 1 : f32 :: NAN } , dict! { 1 : f32 :: NAN } ) ; // yes apparently Godot considers these equal
332
353
assert_ne ! ( dict! { "foo" : "bar" } , dict! { "bar" : "foo" } ) ;
354
+
355
+ // Changed in https://github.com/godotengine/godot/pull/74588.
356
+ #[ cfg( before_api = "4.2" ) ]
357
+ assert_eq ! ( dict! { 1 : f32 :: NAN } , dict! { 1 : f32 :: NAN } ) ;
358
+ #[ cfg( since_api = "4.2" ) ]
359
+ assert_ne ! ( dict! { 1 : f32 :: NAN } , dict! { 1 : f32 :: NAN } ) ;
333
360
}
334
361
335
362
#[ itest]
0 commit comments