use rumdl_lib::lint_context::LintContext;
use rumdl_lib::rule::Rule;
use rumdl_lib::rules::MD026NoTrailingPunctuation;
#[test]
fn test_md026_with_kramdown_header_ids() {
let rule = MD026NoTrailingPunctuation::default();
let content = "# This is a heading. {#custom-id}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert!(result[0].message.contains("punctuation"));
let content = "# This is a heading.";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert!(result[0].message.contains("punctuation"));
let content = r#"# First Header. {#first}
## Second Header! {#second}
### Third Header: {#third}
#### Fourth Header; {#fourth}"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 4, "Should flag all headers with trailing punctuation");
let content = r#"# First Header {#first}
## Second Header {#second}"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Should not flag headers without punctuation");
}
#[test]
fn test_md026_fix_preserves_kramdown_ids() {
let rule = MD026NoTrailingPunctuation::default();
let content = "# Header with period. {#my-id}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(fixed, "# Header with period {#my-id}");
let content = "# Header with period.";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(fixed, "# Header with period");
}
#[test]
fn test_md026_complex_kramdown_ids() {
let rule = MD026NoTrailingPunctuation::default();
let content = r#"# Heading. {#id-with-dashes}
## Another. {#id-with-colons:test}
### Yet Another. {#id_with_underscores}
#### Final. {#id123}"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 4, "Should flag all headers with punctuation");
let content = "## Another. {#id.with.dots}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(
result.len(),
0,
"Should not flag - invalid ID not stripped, doesn't end with punctuation"
);
}
#[test]
fn test_md026_with_trailing_hashes_and_ids() {
let rule = MD026NoTrailingPunctuation::default();
let content = "# Heading # {#id}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Should not flag when no punctuation");
let content = "# Heading. # {#id}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1, "Should flag punctuation even with custom ID");
let content = "# Heading. #";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
}
#[test]
fn test_md026_false_positives() {
let rule = MD026NoTrailingPunctuation::default();
let content = "# Heading. {custom-id}";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(
result.len(),
0,
"Should not flag - ends with curly brace not punctuation"
);
let content = "# Heading {#id} with more text.";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1, "Should flag - ID is not at the end");
}