mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
convert unrwap to expect and add testing
This commit is contained in:
parent
8a10fa8335
commit
e7b7e88bc9
1 changed files with 22 additions and 1 deletions
|
@ -8,7 +8,7 @@ pub(crate) struct Key(uuid::Bytes);
|
||||||
|
|
||||||
impl From<&[u8]> for Key {
|
impl From<&[u8]> for Key {
|
||||||
fn from(bytes: &[u8]) -> Key {
|
fn from(bytes: &[u8]) -> Key {
|
||||||
Key(bytes.try_into().unwrap())
|
Key(bytes.try_into().expect("expected 16 bytes"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,3 +37,24 @@ impl AsRef<[u8]> for Key {
|
||||||
&self.0[..]
|
&self.0[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from_bytes() {
|
||||||
|
let k: Key = (&[1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16][..]).into();
|
||||||
|
let u: Uuid = k.into();
|
||||||
|
assert_eq!(
|
||||||
|
u,
|
||||||
|
Uuid::parse_str("01020304-0506-0708-090a-0b0c0d0e0f10").unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_from_bytes_bad_len() {
|
||||||
|
let _: Key = (&[1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11][..]).into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue