-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::{std::convert::TryInto, Builder, Uuid}; | ||
|
||
use arbitrary::{Arbitrary, Unstructured}; | ||
|
||
impl Arbitrary<'_> for Uuid { | ||
fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result<Self> { | ||
let b = u | ||
.bytes(16)? | ||
.try_into() | ||
.map_err(|_| arbitrary::Error::NotEnoughData)?; | ||
|
||
Ok(Builder::from_random_bytes(b).into_uuid()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
use crate::{Variant, Version}; | ||
|
||
#[test] | ||
fn test_arbitrary() { | ||
let mut bytes = Unstructured::new(&[ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]); | ||
|
||
let uuid = Uuid::arbitrary(&mut bytes).unwrap(); | ||
|
||
assert_eq!(Some(Version::Random), uuid.get_version()); | ||
assert_eq!(Variant::RFC4122, uuid.get_variant()); | ||
} | ||
|
||
#[test] | ||
fn test_arbitrary_empty() { | ||
let mut bytes = Unstructured::new(&[]); | ||
|
||
// Ensure we don't panic when building an arbitrary `Uuid` | ||
let uuid = Uuid::arbitrary(&mut bytes); | ||
|
||
assert!(uuid.is_err()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[cfg(feature = "arbitrary")] | ||
mod arbitrary_support; | ||
#[cfg(feature = "serde")] | ||
mod serde_support; | ||
#[cfg(feature = "slog")] | ||
mod slog_support; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters