use crate::channels::telegram::rich::table::{
ensure_blank_line_before_block_html, ensure_blank_line_before_tables,
};
#[test]
fn abutting_table_gets_blank_line_inserted() {
let input = "**Tests** (host-diag exits, disk, docker):\n| Check | Result |\n|---|---|\n| uptime | ok |";
let expected = "**Tests** (host-diag exits, disk, docker):\n\n| Check | Result |\n|---|---|\n| uptime | ok |";
assert_eq!(ensure_blank_line_before_tables(input), expected);
}
#[test]
fn blank_line_before_table_is_untouched() {
let input = "Text line:\n\n| Check | Result |\n|---|---|\n| uptime | ok |";
assert_eq!(ensure_blank_line_before_tables(input), input);
}
#[test]
fn table_inside_code_fence_is_untouched() {
let input = "```text\nheader above\n| A | B |\n|---|---|\n```\n";
assert_eq!(ensure_blank_line_before_tables(input), input);
}
#[test]
fn pass_is_idempotent() {
let input = "**Tests**:\n| A | B |\n|---|---|\n| 1 | 2 |";
let once = ensure_blank_line_before_tables(input);
assert_eq!(ensure_blank_line_before_tables(&once), once);
}
#[test]
fn pipe_free_input_is_untouched() {
let input = "# Report\n\nAll clear, no pipes in sight.\n";
assert_eq!(ensure_blank_line_before_tables(input), input);
}
#[test]
fn stray_pipe_prose_is_untouched() {
let input = "cost | value\nno separator here\n| also not a table";
assert_eq!(ensure_blank_line_before_tables(input), input);
}
#[test]
fn blockquote_then_details_gets_blank_line_inserted() {
let input =
"> quoted line here\n<details><summary><b>Context</b></summary>\n\nbody text\n\n</details>";
let expected = "> quoted line here\n\n<details><summary><b>Context</b></summary>\n\nbody text\n\n</details>";
assert_eq!(ensure_blank_line_before_block_html(input), expected);
}
#[test]
fn blockquote_then_details_with_blank_line_is_untouched() {
let input = "> quoted line here\n\n<details><summary><b>Context</b></summary>\n\nbody text\n\n</details>";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn html_opener_inside_code_fence_is_untouched() {
let input = "> quoted line here\n```text\n<details>\n```\n";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn inline_tag_after_blockquote_is_untouched() {
let input = "> quoted line here\n<b>bold</b> inline";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn block_html_pass_is_idempotent() {
let input = "> quoted line here\n<details><summary>s</summary>\n\nbody\n\n</details>";
let expected = "> quoted line here\n\n<details><summary>s</summary>\n\nbody\n\n</details>";
assert_eq!(ensure_blank_line_before_block_html(input), expected);
let once = ensure_blank_line_before_block_html(input);
assert_eq!(ensure_blank_line_before_block_html(&once), once);
}
#[test]
fn blockquote_then_paragraph_is_untouched() {
let input = "> quoted line one\n> quoted line two\nplain paragraph";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn closing_tag_and_comment_after_blockquote_are_untouched() {
let input = "> quoted line here\n</details>\n<!-- note -->";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn blockquote_then_multiline_html_opener_gets_one_blank_line() {
let input = "> line one\n> line two\n> line three\n<pre>code</pre>";
let expected = "> line one\n> line two\n> line three\n\n<pre>code</pre>";
assert_eq!(ensure_blank_line_before_block_html(input), expected);
}
#[test]
fn html_opener_without_a_preceding_quote_is_untouched() {
let input = "plain line\n<details>\nbody\n</details>";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn html_free_input_is_untouched() {
let input = "> quoted line here\nplain text, no tags at all";
assert_eq!(ensure_blank_line_before_block_html(input), input);
}
#[test]
fn uppercase_and_attributed_openers_are_detected() {
let input = "> quoted line here\n<DETAILS open class=\"x\">\nbody\n</DETAILS>";
let expected = "> quoted line here\n\n<DETAILS open class=\"x\">\nbody\n</DETAILS>";
assert_eq!(ensure_blank_line_before_block_html(input), expected);
}
#[test]
fn pass_reaches_the_canonical_rich_entry() {
let input = "> quoted line here\n<details><summary>s</summary>\n\nbody\n\n</details>";
let normalized = crate::channels::telegram::rich::table::normalize_tables(input);
assert!(
normalized.contains("> quoted line here\n\n<details>"),
"canonical entry did not terminate the quote run: {normalized:?}"
);
}