//! Tier-1 list-item layout (Phase EE).
//!
//! Tier-2's `handle_li` handles two layout shapes that Tier-1 used to
//! get wrong:
//!   * `<li><p>text</p></li>` — the `<p>` is the first block child of
//!     the list item, so the text follows the bullet inline (`- text`).
//!     Tier-1 used to emit `- \n\nText` (bullet on its own line).
//!   * `<li><p>foo</p><pre>bar</pre></li><li>baz</li>` — loose list:
//!     because the first item has block children, the next bullet
//!     starts after a blank line.  Tier-1 used to emit them tight.
//!   * Multi-line text inside `<code>` was being whitespace-collapsed;
//!     Tier-2 preserves it verbatim like `<pre>`.

#![cfg(feature = "testkit")]

use html_to_markdown_rs::{ConversionOptions, TierStrategy, convert};

fn tier1(html: &str) -> String {
    let opts = ConversionOptions {
        tier_strategy: TierStrategy::Tier1,
        extract_metadata: false,
        ..ConversionOptions::default()
    };
    convert(html, Some(opts)).unwrap().content.unwrap_or_default()
}

fn tier2(html: &str) -> String {
    let opts = ConversionOptions {
        tier_strategy: TierStrategy::Tier2,
        extract_metadata: false,
        ..ConversionOptions::default()
    };
    convert(html, Some(opts)).unwrap().content.unwrap_or_default()
}

fn assert_matches(html: &str) {
    let t1 = tier1(html);
    let t2 = tier2(html);
    assert_eq!(
        t1, t2,
        "tier1 diverged from tier2\ninput: {html:?}\ntier1: {t1:?}\ntier2: {t2:?}"
    );
}

#[test]
fn paragraph_inside_list_item_inline() {
    assert_matches("<ul><li><p>x</p></li></ul>");
}

#[test]
fn paragraph_inside_ordered_list_item_inline() {
    assert_matches("<ol><li><p>x</p></li></ol>");
}

#[test]
fn loose_list_after_block_child_emits_blank_line() {
    assert_matches("<ul><li><p>a</p><pre>code</pre></li><li>b</li></ul>");
}

#[test]
fn tight_list_no_blank_line() {
    assert_matches("<ul><li>a</li><li>b</li></ul>");
}

#[test]
fn code_preserves_whitespace_runs_verbatim() {
    assert_matches("<p><code>a   b</code></p>");
}

#[test]
fn code_preserves_newlines_verbatim() {
    assert_matches("<p><code>line1\n   line2</code></p>");
}
