From 764eb293bd61d878fb1b3d54f5d24dac214e8529 Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Mon, 17 Jun 2024 14:03:56 -0400 Subject: [PATCH] Add test case for disabling #[non_exhaustive] --- .../src/common/v2/test_oneof_nonexhaustive.rs | 15 +++++++++++++++ .../common/v2/test_oneof_nonexhaustive_pb.proto | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs create mode 100644 test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive_pb.proto diff --git a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs new file mode 100644 index 000000000..9353a53cc --- /dev/null +++ b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs @@ -0,0 +1,15 @@ +use protobuf::OneofFull; +use protobuf_test_common::*; + +use super::test_oneof_nonexhaustive_pb::*; + +#[test] +fn test_oneof_nonexhaustive_disabled() { + use message_with_oneof_nonexhaustive_disabled::One; + match MessageWithOneofNonexhaustiveDisabled::default().one { + None => (), + Some(one) => match one { + One::FirstField(_) | One::SecondField(_) => (), + }, + } +} diff --git a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive_pb.proto b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive_pb.proto new file mode 100644 index 000000000..8afde37e9 --- /dev/null +++ b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive_pb.proto @@ -0,0 +1,14 @@ +syntax = "proto2"; + +import "rustproto.proto"; + +package test_oneof; + +message MessageWithOneofNonexhaustiveDisabled{ + option (rustproto.oneofs_non_exhaustive) = false; + + oneof one { + uint32 first_field = 1; + string second_field = 2; + } +}