Skip to content

Commit

Permalink
test(boxed_field): Box an oneof field (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspermeijn authored Feb 7, 2025
1 parent ac98f0f commit 3de8526
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn main() {

prost_build::Config::new()
.boxed("Foo.bar")
.boxed("Foo.oneof_field.box_qux")
.compile_protos(&[src.join("boxed_field.proto")], includes)
.unwrap();

Expand Down
4 changes: 4 additions & 0 deletions tests/src/boxed_field.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ package boxed_field;

message Foo {
Bar bar = 1;
oneof oneof_field {
string baz = 2;
Bar box_qux = 3;
}
}

message Bar {
Expand Down
11 changes: 9 additions & 2 deletions tests/src/boxed_field.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
include!(concat!(env!("OUT_DIR"), "/boxed_field.rs"));

use self::foo::OneofField;

#[test]
/// Confirm `Foo::bar` is boxed by creating an instance
fn test_bar_is_boxed() {
/// Confirm `Foo::bar` and `OneofField::BoxQux` is boxed by creating an instance
fn test_boxed_field() {
use alloc::boxed::Box;
let _ = Foo {
bar: Some(Box::new(Bar {})),
oneof_field: Some(OneofField::BoxQux(Box::new(Bar {}))),
};
let _ = Foo {
bar: Some(Box::new(Bar {})),
oneof_field: Some(OneofField::Baz("hello".into())),
};
}

0 comments on commit 3de8526

Please sign in to comment.