Implement protobuf enum and message generation
Add `write_enum` and `write_message` to generate Rust enums and structs from protobuf descriptors. Update the generator tests to support the updated `generate_rust_code` signature.
This commit is contained in:
@@ -30,8 +30,8 @@ fn test_generated_code_builds() {
|
||||
let set = roto::proto_gen::google::protobuf::descriptor::FileDescriptorSet::new(&set_buf)
|
||||
.expect("Failed to create FileDescriptorSet");
|
||||
|
||||
let generated_code = roto::generator::generate_rust_code(&set);
|
||||
assert!(!generated_code.is_empty(), "Generated code should not be empty");
|
||||
let generated_files = roto::generator::generate_rust_code(&set, None, false);
|
||||
assert!(!generated_files.is_empty(), "Generated code should not be empty");
|
||||
|
||||
// 2. Setup a temporary Cargo project to verify the code builds
|
||||
let root = std::env::current_dir().expect("Failed to get current directory");
|
||||
@@ -62,7 +62,12 @@ fn test_generated_code_builds() {
|
||||
// 4. Write the generated code to src/lib.rs
|
||||
// The generated code uses `use crate::{...}`, but it's now in a separate crate.
|
||||
// Replace `crate` with `roto` to reference the types in the dependency.
|
||||
let final_code = generated_code.replace("use crate::", "use roto::");
|
||||
let mut all_code = String::new();
|
||||
for (_, content) in generated_files {
|
||||
all_code.push_str(&content);
|
||||
all_code.push_str("\n");
|
||||
}
|
||||
let final_code = all_code.replace("use crate::", "use roto::");
|
||||
let lib_path = temp_project_dir.join("src/lib.rs");
|
||||
fs::write(lib_path, final_code).expect("Failed to write generated code to src/lib.rs");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user