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");
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);
assert_eq!(service.methods[0].name, "Echo");
assert_eq!(service.methods[1].name, "Ping");
let code = generate_service_code(service).expect("Failed to generate 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"
);
println!("Generated code:\n{}", code);
}