From 25ae91f0d2129f60a95318c41864095b37d22323 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 4 Aug 2023 23:46:02 +0000 Subject: [PATCH] `array` tests --- src/rstd/atomic/array.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rstd/atomic/array.rs b/src/rstd/atomic/array.rs index 7435f26..33edbfb 100644 --- a/src/rstd/atomic/array.rs +++ b/src/rstd/atomic/array.rs @@ -55,3 +55,29 @@ impl CInliningAtomic for [u8; N] { impl ConstSizeAtomic for [u8; N] { const SIZE: usize = N; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn cannot_parse_array() { + assert_eq!(<[u8; 3]>::parse_slice(&[1, 2, 3]).unwrap(), [1, 2, 3]); + } + + #[test] + fn cannot_parse_undersized_slice() { + assert_eq!( + <[u8; 2]>::parse_slice(&[0, 0, 0, 0]).unwrap_err(), + ArrayParseError::ExtraData(2), + ); + } + + #[test] + fn cannot_parse_oversized_slice() { + assert_eq!( + <[u8; 4]>::parse_slice(&[0, 0]).unwrap_err(), + ArrayParseError::Eof + ); + } +}