use typescript_webidl::parse;
#[test]
fn test_parse_valid_webidl() {
let idl = r#"
interface Test {
attribute string name;
}
"#;
let result = parse(idl);
println!("Parsing result: {:?}", result);
assert!(result.is_ok(), "解析有效的 WebIDL 应该成功");
let root = result.unwrap();
println!("Root items: {:?}", root.items);
println!("Number of items: {}", root.items.len());
}
#[test]
fn test_parse_invalid_webidl() {
let invalid_idl = r#"
interface Test {
attribute string name
}
"#;
let result = parse(invalid_idl);
println!("Invalid WebIDL parsing result: {:?}", result);
if let Err(error) = result {
println!("Error message: '{}'", error);
assert!(!error.is_empty(), "错误信息应该非空");
}
}
#[test]
fn test_convert_to_typescript() {
let idl = r#"
interface Test {
attribute string name;
}
"#;
let result = parse(idl);
println!("Parsing result: {:?}", result);
if let Ok(root) = result {
println!("Root items: {:?}", root.items);
let typescript = typescript_webidl::convert_to_typescript(&root);
println!("Conversion result: '{}'", typescript);
}
}