synapse-codegen 0.0.2

Code generation from protobuf service definitions for Synapse
Documentation
//! Integration test for code generation

use std::path::Path;
use synapse_codegen::{generate_service_code, parse_proto_file};

#[test]
fn test_codegen_generates_valid_rust() {
    let proto_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/test.proto");

    // Parse the proto file
    let services = parse_proto_file(&proto_path).expect("Failed to parse proto");

    assert_eq!(services.len(), 1, "Should have one service");

    let service = &services[0];
    assert_eq!(service.service_name, "EchoService");
    assert_eq!(service.package, "test.v1");
    assert_eq!(service.methods.len(), 2);

    // Check method names
    assert_eq!(service.methods[0].name, "Echo");
    assert_eq!(service.methods[1].name, "Ping");

    // Generate code
    let code = generate_service_code(service).expect("Failed to generate code");

    // Basic sanity checks on generated code
    assert!(
        code.contains("pub trait EchoService"),
        "Should contain trait definition"
    );
    assert!(code.contains("async fn echo"), "Should contain echo method");
    assert!(code.contains("async fn ping"), "Should contain ping method");
    assert!(
        code.contains("pub struct EchoServiceClient"),
        "Should contain client struct"
    );
    assert!(
        code.contains("pub struct EchoServiceRouter"),
        "Should contain router struct"
    );
    assert!(
        code.contains("InterfaceRegistration"),
        "Should use InterfaceRegistration"
    );

    // Print generated code for inspection
    println!("Generated code:\n{}", code);
}