#![allow(clippy::unwrap_used)]
use flowmark::config::ListSpacing;
use flowmark::fill_markdown;
fn fmt(input: &str) -> String {
fill_markdown(input, true, 88, false, false, false, false, None, ListSpacing::Preserve)
}
#[test]
fn syntactic_image_inline_no_title() {
let input = "\n";
assert_eq!(fmt(input), "\n");
}
#[test]
fn syntactic_image_inline_with_double_quoted_title() {
let input = "\n";
assert_eq!(fmt(input), "\n");
}
#[test]
fn syntactic_image_inline_empty_alt() {
let input = "\n";
assert_eq!(fmt(input), "\n");
}
#[test]
fn syntactic_image_full_ref() {
let input = "![alt][img]\n\n[img]: https://example.com/img.png\n";
let expected = "\n\n[img]: https://example.com/img.png\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_full_ref_with_title() {
let input = "![alt][img]\n\n[img]: https://example.com/img.png \"My title\"\n";
let expected = "\n\n[img]: https://example.com/img.png \"My title\"\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_full_ref_case_insensitive_label() {
let input = "![alt][IMG]\n\n[Img]: https://example.com/img.png\n";
let expected = "\n\n[img]: https://example.com/img.png\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_collapsed_ref() {
let input = "![alt][]\n\n[alt]: https://example.com/img.png\n";
let expected = "\n\n[alt]: https://example.com/img.png\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_shortcut_ref() {
let input = "![alt]\n\n[alt]: https://example.com/img.png\n";
let expected = "\n\n[alt]: https://example.com/img.png\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_label_with_spaces_and_punctuation() {
let input = "![Logo][company logo]\n\n[company logo]: https://example.com/logo.png\n";
let expected =
"\n\n[company logo]: https://example.com/logo.png\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_image_missing_definition_pass_through() {
let input = "Some ![alt][missing] text.\n";
let out = fmt(input);
assert!(
!out.contains('\u{F000}') && !out.contains('\u{F001}') && !out.contains('\u{F002}'),
"missing-def image must not leak PUA markers, got: {out}"
);
}
#[test]
fn syntactic_link_inline_no_title() {
let input = "[click](https://example.com)\n";
assert_eq!(fmt(input), "[click](https://example.com)\n");
}
#[test]
fn syntactic_link_inline_with_title() {
let input = "[click](https://example.com \"My title\")\n";
assert_eq!(fmt(input), "[click](https://example.com \"My title\")\n");
}
#[test]
fn syntactic_link_autolink_angle_bracket() {
let input = "<https://example.com>\n";
assert_eq!(fmt(input), "<https://example.com>\n");
}
#[test]
fn syntactic_link_full_ref_preserved() {
let input = "[click here][link]\n\n[link]: https://example.com\n";
let expected = "[click here][link]\n\n[link]: https://example.com\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_full_ref_with_title_preserved() {
let input = "[click][link]\n\n[link]: https://example.com \"A title\"\n";
let expected = "[click][link]\n\n[link]: https://example.com \"A title\"\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_collapsed_ref_preserved() {
let input = "[link][]\n\n[link]: https://example.com\n";
let expected = "[link][]\n\n[link]: https://example.com\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_shortcut_ref_normalized_to_collapsed() {
let input = "[link]\n\n[link]: https://example.com\n";
let expected = "[link][]\n\n[link]: https://example.com\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_full_ref_case_insensitive_label() {
let input = "[click][LINK]\n\n[Link]: https://example.com\n";
let expected = "[click][link]\n\n[link]: https://example.com\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_label_with_spaces_and_punctuation() {
let input = "[School][St. John's School]\n\n[St. John's School]: https://example.com\n";
let expected = "[School][st. john's school]\n\n[st. john's school]: https://example.com\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_link_missing_definition_pass_through() {
let input = "Some [text][missing] more.\n";
let out = fmt(input);
assert!(
!out.contains('\u{F000}') && !out.contains('\u{F001}') && !out.contains('\u{F002}'),
"missing-def link must not leak PUA markers, got: {out}"
);
}
#[test]
fn syntactic_badge_inline_image_in_full_ref_link() {
let input = "[][url]\n\n[url]: https://example.com/page\n";
let expected =
"[][url]\n\n[url]: https://example.com/page\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_badge_full_ref_image_in_full_ref_link() {
let input = "[![alt][img]][url]\n\n[img]: https://example.com/img.png\n[url]: https://example.com/page\n";
let expected = "[][url]\n\n[img]: https://example.com/img.png\n[url]: https://example.com/page\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_badge_collapsed_ref_image_in_full_ref_link() {
let input =
"[![alt][]][url]\n\n[alt]: https://example.com/img.png\n[url]: https://example.com/page\n";
let expected = "[][url]\n\n[alt]: https://example.com/img.png\n[url]: https://example.com/page\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_badge_shortcut_ref_image_in_full_ref_link() {
let input =
"[![alt]][url]\n\n[alt]: https://example.com/img.png\n[url]: https://example.com/page\n";
let expected = "[][url]\n\n[alt]: https://example.com/img.png\n[url]: https://example.com/page\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_badge_inline_image_in_inline_link() {
let input = "[](https://example.com/page)\n";
let expected = "[](https://example.com/page)\n";
assert_eq!(fmt(input), expected);
}
#[test]
fn syntactic_code_single_backtick() {
let input = "Use `let x = 5;` here.\n";
assert_eq!(fmt(input), "Use `let x = 5;` here.\n");
}
#[test]
fn syntactic_code_double_backtick_with_inner_backtick() {
let input = "Use `` ` `` for backticks.\n";
assert_eq!(fmt(input), "Use `` ` `` for backticks.\n");
}
#[test]
fn syntactic_emph_asterisk() {
let input = "Some *emphasized* text.\n";
assert_eq!(fmt(input), "Some *emphasized* text.\n");
}
#[test]
fn syntactic_strong_asterisk() {
let input = "Some **bold** text.\n";
assert_eq!(fmt(input), "Some **bold** text.\n");
}
#[test]
fn syntactic_strong_emph_nested() {
let input = "Some ***bold and emphasized*** text.\n";
assert_eq!(fmt(input), "Some ***bold and emphasized*** text.\n");
}
#[test]
fn syntactic_strikethrough_basic() {
let input = "Some ~~deleted~~ text.\n";
assert_eq!(fmt(input), "Some ~~deleted~~ text.\n");
}
#[test]
fn syntactic_linebreak_backslash() {
let input = "Line one\\\nLine two\n";
assert_eq!(fmt(input), "Line one\\\nLine two\n");
}
#[test]
fn syntactic_footnote_reference_basic() {
let input = "See note[^1] here.\n\n[^1]: The note body.\n";
let out = fmt(input);
assert!(out.contains("[^1]"), "footnote reference should round-trip: {out}");
assert!(out.contains("[^1]: The note body."), "footnote def should round-trip: {out}");
}
#[test]
fn syntactic_bare_url_autolink_no_angle_brackets() {
let input = "Visit https://example.com today.\n";
assert_eq!(fmt(input), "Visit https://example.com today.\n");
}
#[test]
fn syntactic_html_inline_simple_tag() {
let input = "Text with <span>inline html</span> here.\n";
assert_eq!(fmt(input), "Text with <span>inline html</span> here.\n");
}