Skip to content

Commit fa56c3d

Browse files
Add tests
1 parent 5dede66 commit fa56c3d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ optional = true
2222

2323
[features]
2424
cbor = ["serde_cbor"]
25+
26+
[dev-dependencies]
27+
serde_test = "1.0.176"

src/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,33 @@ impl<'de, const N: usize> Deserialize<'de> for Bytes<N> {
389389
}
390390
}
391391

392+
#[cfg(test)]
393+
mod tests_serde {
394+
use super::*;
395+
use serde_test::{assert_tokens, Token};
396+
397+
#[test]
398+
fn all() {
399+
let mut bytes = Bytes::<0>::new();
400+
assert!(bytes.push(1).is_err());
401+
assert_tokens(&bytes, &[Token::Bytes(&[])]);
402+
403+
let mut bytes = Bytes::<16>::new();
404+
bytes.push(1).unwrap();
405+
assert_tokens(&bytes, &[Token::Bytes(&[1])]);
406+
assert!(bytes.extend_from_slice(&[2; 16]).is_err());
407+
assert_eq!(&**bytes, &[1]);
408+
assert!(bytes.extend_from_slice(&[2; 15]).is_ok());
409+
assert_eq!(&**bytes, &[1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]);
410+
assert_tokens(
411+
&bytes,
412+
&[Token::Bytes(&[
413+
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
414+
])],
415+
);
416+
}
417+
}
418+
392419
#[cfg(test)]
393420
#[cfg(feature = "cbor")]
394421
mod tests {

0 commit comments

Comments
 (0)