Skip to content

Commit 2c264f2

Browse files
committed
Check endianness-invariance.
1 parent cb9c5a8 commit 2c264f2

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/ext/uuid.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use uuid::Uuid;
2-
use crate::derive::convert::ConvertFrom;
31
use crate::convert::impl_convert;
2+
use crate::derive::convert::ConvertFrom;
3+
use uuid::Uuid;
44

55
type UuidConversion = [u8; 16];
66

@@ -21,13 +21,24 @@ impl_convert!(uuid::Uuid, UuidConversion);
2121
#[cfg(test)]
2222
mod tests {
2323
use alloc::vec::Vec;
24+
use std::str::FromStr;
2425
use uuid::Uuid;
2526

2627
#[test]
2728
fn test() {
2829
assert!(crate::decode::<Uuid>(&crate::encode(&Uuid::new_v4())).is_ok());
2930
}
3031

32+
// By running this test on architectures with different endianness,
33+
// we ensure our implementation is endianness-invariant.
34+
#[test]
35+
fn consistency() {
36+
assert_eq!(
37+
crate::encode(&Uuid::from_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8").unwrap()),
38+
[0, 161, 162, 163, 164, 177, 178, 193, 194, 209, 210, 211, 212, 213, 214, 215, 216]
39+
)
40+
}
41+
3142
fn bench_data() -> Vec<Uuid> {
3243
crate::random_data(1000)
3344
.into_iter()

0 commit comments

Comments
 (0)