Skip to content

Commit

Permalink
coverage for enum lists in dynamic_list
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Nov 29, 2023
1 parent 4fb0dd1 commit 2b06400
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions capnpc/test/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,15 @@ pub fn dynamic_init_test_message(mut builder: ::capnp::dynamic_struct::Builder<'
.set_named("textField", "structlist 3".into())
.unwrap();
}
{
let mut enum_list: capnp::dynamic_list::Builder<'_> = builder
.reborrow()
.initn_named("enumList", 2)
.unwrap()
.downcast();
enum_list.set(0, TestEnum::Foo.into()).unwrap();
enum_list.set(1, TestEnum::Garply.into()).unwrap();
}
}

pub fn dynamic_check_test_message(reader: capnp::dynamic_struct::Reader<'_>) {
Expand Down Expand Up @@ -914,6 +923,37 @@ pub fn dynamic_check_test_message(reader: capnp::dynamic_struct::Reader<'_>) {
.downcast::<capnp::text::Reader<'_>>()
);
}
{
let enum_list: capnp::dynamic_list::Reader<'_> =
reader.get_named("enumList").unwrap().downcast();
assert_eq!(2, enum_list.len());
assert_eq!(
"foo",
enum_list
.get(0)
.unwrap()
.downcast::<capnp::dynamic_value::Enum>()
.get_enumerant()
.unwrap()
.unwrap()
.get_proto()
.get_name()
.unwrap()
);
assert_eq!(
"garply",
enum_list
.get(1)
.unwrap()
.downcast::<capnp::dynamic_value::Enum>()
.get_enumerant()
.unwrap()
.unwrap()
.get_proto()
.get_name()
.unwrap()
);
}
}

pub fn dynamic_check_test_message_builder(mut builder: capnp::dynamic_struct::Builder<'_>) {
Expand Down Expand Up @@ -1333,4 +1373,36 @@ pub fn dynamic_check_test_message_builder(mut builder: capnp::dynamic_struct::Bu
.downcast::<capnp::text::Reader<'_>>()
);
}
{
let mut enum_list: capnp::dynamic_list::Builder<'_> =
builder.reborrow().get_named("enumList").unwrap().downcast();
assert_eq!(2, enum_list.len());
assert_eq!(
"foo",
enum_list
.reborrow()
.get(0)
.unwrap()
.downcast::<capnp::dynamic_value::Enum>()
.get_enumerant()
.unwrap()
.unwrap()
.get_proto()
.get_name()
.unwrap()
);
assert_eq!(
"garply",
enum_list
.get(1)
.unwrap()
.downcast::<capnp::dynamic_value::Enum>()
.get_enumerant()
.unwrap()
.unwrap()
.get_proto()
.get_name()
.unwrap()
);
}
}

0 comments on commit 2b06400

Please sign in to comment.