mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-02 07:20:40 +00:00
split up v1 tests
This commit is contained in:
parent
69b9014747
commit
128befda46
63
src/v1.rs
63
src/v1.rs
@ -286,36 +286,47 @@ mod tests {
|
||||
let node = [1, 2, 3, 4, 5, 6];
|
||||
let context = Context::new(0);
|
||||
|
||||
{
|
||||
let uuid = Uuid::new_v1(
|
||||
Timestamp::from_unix(&context, time, time_fraction),
|
||||
&node,
|
||||
);
|
||||
let uuid = Uuid::new_v1(
|
||||
Timestamp::from_unix(&context, time, time_fraction),
|
||||
&node,
|
||||
);
|
||||
|
||||
assert_eq!(uuid.get_version(), Some(Version::Mac));
|
||||
assert_eq!(uuid.get_variant(), Variant::RFC4122);
|
||||
assert_eq!(
|
||||
uuid.to_hyphenated().to_string(),
|
||||
"20616934-4ba2-11e7-8000-010203040506"
|
||||
);
|
||||
assert_eq!(uuid.get_version(), Some(Version::Mac));
|
||||
assert_eq!(uuid.get_variant(), Variant::RFC4122);
|
||||
assert_eq!(
|
||||
uuid.to_hyphenated().to_string(),
|
||||
"20616934-4ba2-11e7-8000-010203040506"
|
||||
);
|
||||
|
||||
let ts = uuid.get_timestamp().unwrap().to_rfc4122();
|
||||
let ts = uuid.get_timestamp().unwrap().to_rfc4122();
|
||||
|
||||
assert_eq!(ts.0 - 0x01B2_1DD2_1381_4000, 14_968_545_358_129_460);
|
||||
assert_eq!(ts.1, 0);
|
||||
};
|
||||
assert_eq!(ts.0 - 0x01B2_1DD2_1381_4000, 14_968_545_358_129_460);
|
||||
|
||||
{
|
||||
let uuid2 = Uuid::new_v1(
|
||||
Timestamp::from_unix(&context, time, time_fraction),
|
||||
&node,
|
||||
);
|
||||
// Ensure parsing the same UUID produces the same timestamp
|
||||
let parsed = Uuid::parse_str("20616934-4ba2-11e7-8000-010203040506").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
uuid2.to_hyphenated().to_string(),
|
||||
"20616934-4ba2-11e7-8001-010203040506"
|
||||
);
|
||||
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 1)
|
||||
};
|
||||
assert_eq!(uuid.get_timestamp().unwrap(), parsed.get_timestamp().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
|
||||
fn test_new_v1_context() {
|
||||
let time: u64 = 1_496_854_535;
|
||||
let time_fraction: u32 = 812_946_000;
|
||||
let node = [1, 2, 3, 4, 5, 6];
|
||||
let context = Context::new(0);
|
||||
|
||||
let uuid1 = Uuid::new_v1(
|
||||
Timestamp::from_unix(&context, time, time_fraction),
|
||||
&node,
|
||||
);
|
||||
|
||||
let uuid2 = Uuid::new_v1(
|
||||
Timestamp::from_unix(&context, time, time_fraction),
|
||||
&node,
|
||||
);
|
||||
|
||||
assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 0);
|
||||
assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user