-
-
Notifications
You must be signed in to change notification settings - Fork 253
Rename builtin hash()
-> hash_u32()
; add tests
#1366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
229dd2c
64fc5b3
9e536c3
74d15b6
9bde1ee
67b1a74
641a271
7a83936
3f8af8d
6622ede
2dd05c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,17 @@ pub mod inner { | |
pub use crate::gen::builtin_classes::*; | ||
} | ||
|
||
// common hashing macro implementer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment could as well be removed, the macro name itself contains more information than it 🙂 |
||
#[macro_export] | ||
macro_rules! declare_hash_u32_method { | ||
($ ($docs:tt)+ ) => { | ||
$( $docs )+ | ||
pub fn hash_u32(&self) -> u32 { | ||
self.as_inner().hash().try_into().expect("Godot hashes are uint32_t") | ||
} | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Conversion functions | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -713,13 +713,22 @@ fn variant_hash() { | |||||
]; | ||||||
|
||||||
for variant in hash_is_not_0 { | ||||||
assert_ne!(variant.hash(), 0) | ||||||
assert_ne!(variant.hash_u32(), 0); | ||||||
} | ||||||
for variant in self_equal { | ||||||
assert_eq!(variant.hash(), variant.hash()) | ||||||
assert_eq!(variant.hash_u32(), variant.hash_u32()); | ||||||
} | ||||||
|
||||||
assert_eq!(Variant::nil().hash(), 0); | ||||||
let v_first = 1.to_variant(); | ||||||
let v_second = 1.to_variant(); | ||||||
let v_third = "hello".to_variant(); | ||||||
|
||||||
assert_eq!(v_first, v_second); | ||||||
assert_eq!(v_first.hash_u32(), v_second.hash_u32()); | ||||||
assert_ne!(v_first, v_third); | ||||||
assert_ne!(v_first.hash_u32(), v_third.hash_u32()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not guaranteed, just quite likely. The relation is:
and not
It's OK to keep this, but there should be a comment such as:
Suggested change
everywhere, also in other such tests. |
||||||
|
||||||
assert_eq!(Variant::nil().hash_u32(), 0); | ||||||
|
||||||
// It's not guaranteed that different object will have different hash, but it is | ||||||
// extremely unlikely for a collision to happen. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also indentation of subsequent lines.