use crate::channels::slack::table_convert::structure_to_slack;
#[test]
fn a_table_becomes_labels_and_continuations() {
let input = "| Metric | Before | After |\n\
|---|---|---|\n\
| RestartCount | 272 | 0 |\n\
| Uptime | 30 min | 1h 44m |";
let out = structure_to_slack(input);
assert!(!out.contains('|'), "pipes survived: {out}");
assert!(out.contains("*RestartCount*"), "missing label: {out}");
assert!(out.contains("└ Before: 272"), "missing continuation: {out}");
assert!(out.contains("└ After: 0"), "missing continuation: {out}");
assert!(out.contains("*Uptime*"), "second row lost: {out}");
}
#[test]
fn a_two_column_table_collapses_to_one_line_per_row() {
let input = "| Check | Result |\n|---|---|\n| Listening | 0.0.0.0:3310 |";
let out = structure_to_slack(input);
assert_eq!(out, "*Listening* — 0.0.0.0:3310");
}
#[test]
fn prose_with_pipes_is_not_treated_as_a_table() {
let input = "Run `ps aux | grep clamd` and check the output.";
assert_eq!(structure_to_slack(input), input);
}
#[test]
fn a_row_without_a_separator_is_left_alone() {
let input = "| this looks like a row |\nbut nothing follows it";
assert_eq!(structure_to_slack(input), input);
}
#[test]
fn a_table_inside_a_code_fence_is_untouched() {
let input = "```\n| a | b |\n|---|---|\n| 1 | 2 |\n```";
assert_eq!(structure_to_slack(input), input);
}
#[test]
fn headings_become_bold_caps() {
let out = structure_to_slack("## Container state\nAll good.");
assert!(out.starts_with("*CONTAINER STATE*"), "got: {out}");
assert!(!out.contains('#'), "hashes survived: {out}");
}
#[test]
fn a_divider_precedes_every_heading_but_the_first() {
let out = structure_to_slack("# One\nbody\n\n## Two\nbody");
assert!(!out.starts_with("---"), "message opened with a rule: {out}");
assert_eq!(out.matches("---").count(), 1, "expected one divider: {out}");
assert!(out.contains("*TWO*"));
}
#[test]
fn a_heading_inside_a_code_fence_is_untouched() {
let input = "```\n# not a heading\n```";
assert_eq!(structure_to_slack(input), input);
}
#[test]
fn ordinary_prose_is_untouched() {
let input = "Verified live at 00:47 UTC.\n\nEvery figure read off the box.";
assert_eq!(structure_to_slack(input), input);
}
#[test]
fn a_table_under_a_heading_converts_both() {
let input = "## What shipped\n| Commit | Status |\n|---|---|\n| a01fe4c3 | live |";
let out = structure_to_slack(input);
assert!(out.contains("*WHAT SHIPPED*"), "got: {out}");
assert!(out.contains("*a01fe4c3* — live"), "got: {out}");
assert!(!out.contains('|'), "got: {out}");
}