typescript-webidl 0.0.1

WebIDL parser and TypeScript converter for Rusty TypeScript
Documentation
/// WebIDL 解析模块测试
use typescript_webidl::parse;

#[test]
fn test_parse_valid_webidl() {
    // 测试解析有效的 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());

    // 暂时注释掉这个断言,先了解解析行为
    // assert!(!root.items.is_empty(), "解析结果应该包含至少一个项");
}

#[test]
fn test_parse_invalid_webidl() {
    // 测试解析无效的 WebIDL 语法
    let invalid_idl = r#"
        interface Test {
            attribute string name
        }
    "#;

    let result = parse(invalid_idl);
    println!("Invalid WebIDL parsing result: {:?}", result);

    // 暂时注释掉这个断言,先了解解析行为
    // assert!(result.is_err(), "解析无效的 WebIDL 应该失败");

    if let Err(error) = result {
        println!("Error message: '{}'", error);
        assert!(!error.is_empty(), "错误信息应该非空");
    }
}

#[test]
fn test_convert_to_typescript() {
    // 测试将 WebIDL 转换为 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);

        // 暂时注释掉这些断言,先了解转换行为
        // assert!(!typescript.is_empty(), "转换结果应该非空");
        // assert!(typescript.contains("interface Test"), "转换结果应该包含 Test 接口");
    }
}