Add support for Protobuf oneof fields in generator
Generate `which_<oneof>` methods and corresponding enums to handle oneof fields in generated messages. Also add `has_<field>` helper methods for all fields.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use roto_codegen::generator::generate_rust_code;
|
||||
use roto_codegen::google::protobuf::descriptor::{
|
||||
DescriptorProto, FieldDescriptorProto, FileDescriptorSet,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn test_oneof_generation() {
|
||||
let mut set = FileDescriptorSet::new(b"").unwrap(); // Simplified for testing
|
||||
|
||||
// In a real scenario, we'd build up a FileDescriptorSet from a proto.
|
||||
// For this unit test, we'll manually construct a DescriptorProto that has a oneof.
|
||||
|
||||
// However, generate_rust_code takes a FileDescriptorSet.
|
||||
// Let's mock a simple setup.
|
||||
|
||||
// Since manually constructing FileDescriptorSet is complex, let's instead check if the
|
||||
// generator logic for oneofs produces the expected strings given a DescriptorProto.
|
||||
|
||||
// But the current tests use load_generated_code() which reads from data/request.bin.
|
||||
// Let's see if we can find a way to test just the write_message function or similar.
|
||||
}
|
||||
Reference in New Issue
Block a user