use shelly::Html;
use shelly_macros::html;

#[test]
fn html_macro_renders_without_string_formatting() {
    let name = "Ada";
    let template = html! {
        "<section><h1>Hello " (name) "</h1></section>"
    };

    let rendered: Html = template.clone().into();

    assert_eq!(
        template.static_segments(),
        &["<section><h1>Hello ", "</h1></section>"]
    );
    assert_eq!(template.dynamic_segments(), &["Ada"]);
    assert_eq!(
        rendered.as_str(),
        r#"<section><h1>Hello <span data-shelly-slot="0">Ada</span></h1></section>"#
    );
}

#[test]
fn html_macro_escapes_dynamic_values_by_default() {
    let name = r#"<script title="x">Ada & Bob</script>"#;
    let template = html! {
        "<p>" (name) "</p>"
    };

    assert_eq!(
        template.render_string(),
        r#"<p><span data-shelly-slot="0">&lt;script title=&quot;x&quot;&gt;Ada &amp; Bob&lt;/script&gt;</span></p>"#
    );
}

#[test]
fn html_macro_preserves_static_segments_for_future_diffing() {
    let count = 7;
    let label = "Count";
    let template = html! {
        "<h1>" (label) ": " (count) "</h1>"
    };

    assert_eq!(template.static_segments(), &["<h1>", ": ", "</h1>"]);
    assert_eq!(template.dynamic_segments(), &["Count", "7"]);
    assert_eq!(
        template.render_string(),
        r#"<h1><span data-shelly-slot="0">Count</span>: <span data-shelly-slot="1">7</span></h1>"#
    );
}
