Skip to content

Commit

Permalink
Add tests for heapless::String
Browse files Browse the repository at this point in the history
Signed-off-by: chrysn <[email protected]>
  • Loading branch information
chrysn committed Oct 30, 2024
1 parent 6f03d66 commit cd955e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions minicbor-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ description = "minicbor test suite"
alloc = ["minicbor/alloc"]
std = ["alloc", "minicbor/std", "minicbor/derive"]
derive = ["alloc", "minicbor/derive"]
heapless = ["dep:heapless", "minicbor/heapless"]

[dependencies]
arbitrary = { version = "1.3.2", features = ["derive"] }
heapless = { version = "0.8.0", default-features = false, optional = true }
minicbor = { path = "../minicbor", features = ["half"] }

[dev-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions minicbor-tests/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,11 @@ fn regular_enum() {
assert!(d.skip().unwrap_err().is_end_of_input())
}

#[cfg(feature = "heapless")]
#[test]
fn heapless() {
let original = heapless::String::<20>::try_from("BOR").unwrap();
let bytes = minicbor::to_vec(&original).unwrap();
assert_eq!(&b"cBOR"[..], &bytes[..]);
assert_eq!(original, minicbor::decode::<heapless::String::<20>>(&bytes).unwrap());
}

0 comments on commit cd955e5

Please sign in to comment.