Skip to content

Commit

Permalink
test: Add display length test
Browse files Browse the repository at this point in the history
  • Loading branch information
quininer committed Nov 25, 2023
1 parent 827ae89 commit 193040b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cbor4ii"
version = "0.3.1"
version = "0.3.2"
authors = ["quininer <[email protected]>"]
description = "CBOR: Concise Binary Object Representation"
repository = "https://github.com/quininer/cbor4ii"
Expand All @@ -26,7 +26,7 @@ serde_bytes = "0.11"
data-encoding = "2"
serde_cbor = "0.11"
ciborium = "0.2"
criterion = "0.4"
criterion = "0.5"

[package.metadata.docs.rs]
all-features = true
Expand Down
39 changes: 39 additions & 0 deletions tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,42 @@ fn test_regression_min_i64() {
let min_i64: i64 = from_slice(&buf).unwrap();
assert_eq!(min_i64, i64::MIN);
}

#[test]
fn test_debug_ser_len() {
struct Test {
long: char,
short: char
}

impl fmt::Display for Test {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = (0..257).map(|_| self.long).collect::<String>();
write!(f, "{}", s)?;

for _ in 0..257 {
write!(f, "{}", self.short)?;
}

Ok(())
}
}

impl Serialize for Test {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.collect_str(self)
}
}

let test = Test {
long: 'l',
short: 's'
};

let buf = to_vec(Vec::new(), &test).unwrap();
assert!(dbg!(buf.len()) < 777); // <= 0.3.1
assert!(dbg!(buf.len()) <= 523);
}

0 comments on commit 193040b

Please sign in to comment.