mdtablefix 0.6.1

`mdtablefix` unb0rks and reflows Markdown tables so that each column has a uniform width. When the `--wrap` option is used, it also wraps paragraphs and list items to 80 columns.
Documentation
//! Tests for HTML table conversion to Markdown.

use rstest::rstest;
use super::*;

#[rstest(
    input,
    expected,
    case::basic(html_table(), lines_vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]),
    case::with_attrs(html_table_with_attrs(), lines_vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]),
    case::uppercase(html_table_uppercase(), lines_vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"]),
)]
fn test_convert_html_table_standard(input: Vec<String>, expected: Vec<String>) {
    assert_eq!(convert_html_tables(&input), expected);
}

#[rstest(
    input,
    expected,
    case::colspan(html_table_with_colspan(), lines_vec!["| A |", "| --- |", "| 1 | 2 |"]),
    case::inconsistent(html_table_inconsistent_first_row(), lines_vec!["| A |", "| --- |", "| 1 | 2 |"]),
)]
fn test_convert_html_table_reduced(input: Vec<String>, expected: Vec<String>) {
    assert_eq!(convert_html_tables(&input), expected);
}

#[test]
fn test_convert_html_table_no_header() {
    let expected = lines_vec!["| A | B |", "| --- | --- |", "| 1 | 2 |"];
    assert_eq!(convert_html_tables(&html_table_no_header()), expected);
}

#[test]
fn test_convert_html_table_empty_row() {
    let expected = lines_vec!["| 1 | 2 |", "| --- | --- |"];
    assert_eq!(convert_html_tables(&html_table_empty_row()), expected);
}

#[test]
fn test_convert_html_table_whitespace_header() {
    let expected = lines_vec!["| --- | --- |", "| --- | --- |", "| 1   | 2   |"];
    assert_eq!(
        convert_html_tables(&html_table_whitespace_header()),
        expected
    );
}

#[test]
fn test_convert_html_table_empty() {
    assert!(convert_html_tables(&html_table_empty()).is_empty());
}

#[test]
fn test_convert_html_table_unclosed_returns_original() {
    let html = html_table_unclosed();
    assert_eq!(convert_html_tables(&html), html);
}

#[test]
fn test_convert_html_table_bold_header() {
    let input: Vec<String> = include_lines!("data/bold_header_input.txt");
    let expected: Vec<String> = include_lines!("data/bold_header_expected.txt");
    assert_eq!(convert_html_tables(&input), expected);
}
#[test]
fn preserves_trailing_spaces_in_cells() {
    let input = lines_vec![
        "<table>",
        "<tr><th>H</th></tr>",
        "<tr><td>cell </td></tr>",
        "</table>",
    ];
    let expected = lines_vec![
        "| H |",
        "| --- |",
        "| cell  |",
    ];
    assert_eq!(convert_html_tables(&input), expected);
}

#[rstest(
    input,
    expected,
    case::multiline(
        lines_vec![
            "  <table>",
            "    <tr><th>A</th><th>B</th></tr>",
            "    <tr><td>1</td><td>2</td></tr>",
            "  </table>",
        ],
        lines_vec![
            "  | A | B |",
            "  | --- | --- |",
            "  | 1 | 2 |",
        ]
    ),
    case::surrounding_content(
        lines_vec![
            "  <div>before</div>",
            "  <table>",
            "    <tr><th>A</th><th>B</th></tr>",
            "    <tr><td>1</td><td>2</td></tr>",
            "  </table>",
            "  <p>after</p>",
        ],
        lines_vec![
            "  <div>before</div>",
            "  | A | B |",
            "  | --- | --- |",
            "  | 1 | 2 |",
            "  <p>after</p>",
        ]
    ),
)]
fn converts_indented_html_table_cases(input: Vec<String>, expected: Vec<String>) {
    assert_eq!(convert_html_tables(&input), expected);
}

#[test]
fn nested_html_table_does_not_trigger_premature_flush() {
    let input = lines_vec![
        "<table>",
        "<tr><th>A</th><th>B</th></tr>",
        "<tr><td>",
        "<table>",
        "<tr><th>Inner</th></tr>",
        "<tr><td>x</td></tr>",
        "</table>",
        "</td><td>2</td></tr>",
        "</table>",
    ];
    let output = convert_html_tables(&input);
    assert!(
        output
            .iter()
            .all(|line| !line.contains("<table>") && !line.contains("</table>")),
        "nested structure must be buffered to the outermost </table> and converted as one block, \
         leaving no raw <table>/</table> markers: {output:?}"
    );
    assert!(
        output.iter().any(|line| line.starts_with('|')),
        "expected at least one Markdown table row in {output:?}"
    );
}