use neutron_engine::{parse_tag, parse_attributes, parse_style, normalize_decl, Attribute, StyleDecl, StyleProp};

#[test]
fn test_parse_tag() {
    let result = parse_tag(r#"<Container style="b:#000">"#);
    assert_eq!(result, Some(("Container", r#"style="b:#000""#)));
}

#[test]
fn test_parse_tag_no_attrs() {
    let result = parse_tag("<Body>");
    assert_eq!(result, Some(("Body", "")));
}

#[test]
fn test_parse_attributes() {
    let mut attrs = [Attribute { name: "", value: "" }; 12];
    let count = parse_attributes(r#"style="b:#000" id="Main""#, &mut attrs);
    assert_eq!(count, 2);
    assert_eq!(attrs[0].name, "style");
    assert_eq!(attrs[0].value, "b:#000");
    assert_eq!(attrs[1].name, "id");
    assert_eq!(attrs[1].value, "Main");
}

#[test]
fn test_parse_style() {
    let mut styles = [StyleDecl { name: "", value: "" }; 16];
    let count = parse_style("b:#000; c:#fff", &mut styles);
    assert_eq!(count, 2);
    assert_eq!(styles[0].name, "b");
    assert_eq!(styles[0].value, "#000");
    assert_eq!(styles[1].name, "c");
    assert_eq!(styles[1].value, "#fff");
}

#[test]
fn test_normalize_decl_background() {
    let decl = StyleDecl { name: "b", value: "#000" };
    let prop = normalize_decl(decl);
    match prop {
        StyleProp::Background(color) => assert_eq!(color, "#000"),
        _ => panic!("Expected Background"),
    }
}

#[test]
fn test_normalize_decl_color() {
    let decl = StyleDecl { name: "c", value: "#fff" };
    let prop = normalize_decl(decl);
    match prop {
        StyleProp::Color(color) => assert_eq!(color, "#fff"),
        _ => panic!("Expected Color"),
    }
}

#[test]
fn test_normalize_decl_raw() {
    let decl = StyleDecl { name: "custom", value: "value" };
    let prop = normalize_decl(decl);
    match prop {
        StyleProp::Raw(name, value) => {
            assert_eq!(name, "custom");
            assert_eq!(value, "value");
        }
        _ => panic!("Expected Raw"),
    }
}
