From 2d36ec08057bfbc0f8acd0c1bc503a9b6da388fe Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 23 Oct 2023 19:52:10 -0400 Subject: [PATCH] add simple test for SingleSegmnetAllocator --- capnp/tests/single_segment_allocator.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 capnp/tests/single_segment_allocator.rs diff --git a/capnp/tests/single_segment_allocator.rs b/capnp/tests/single_segment_allocator.rs new file mode 100644 index 000000000..d5fab0c84 --- /dev/null +++ b/capnp/tests/single_segment_allocator.rs @@ -0,0 +1,15 @@ +#![cfg(feature = "alloc")] + +use capnp::message; + +#[test] +pub fn single_segment_allocator() { + let mut buffer = capnp::Word::allocate_zeroed_vec(200); + let allocator = + message::SingleSegmentAllocator::new(capnp::Word::words_to_bytes_mut(&mut buffer[..])); + let mut msg = message::Builder::new(allocator); + msg.set_root("hello world!").unwrap(); + + let s: capnp::text::Reader = msg.get_root_as_reader().unwrap(); + assert_eq!("hello world!", s); +}