use rumdl_lib::lint_context::LintContext;
use rumdl_lib::rule::Rule;
use rumdl_lib::rules::MD031BlanksAroundFences;
#[test]
fn test_kramdown_block_attributes_auto_detected() {
let rule = MD031BlanksAroundFences::default();
let content = r#"# Title
```bash
echo hello
```
{:.wrap}
Some text"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Should auto-detect Kramdown block attributes");
}
#[test]
fn test_non_kramdown_braces_still_flagged() {
let rule = MD031BlanksAroundFences::default();
let content = r#"# Title
```bash
echo hello
```
{not kramdown}
Some 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 non-Kramdown brace lines");
assert!(result[0].message.contains("No blank line after"));
}
#[test]
fn test_kramdown_css_class_variants() {
let rule = MD031BlanksAroundFences::default();
let content1 = r#"```bash
echo hello
```
{:.wrap}"#;
let ctx = LintContext::new(content1, rumdl_lib::config::MarkdownFlavor::Standard, None);
assert!(rule.check(&ctx).unwrap().is_empty());
let content2 = r#"```bash
echo hello
```
{:#my-code}"#;
let ctx = LintContext::new(content2, rumdl_lib::config::MarkdownFlavor::Standard, None);
assert!(rule.check(&ctx).unwrap().is_empty());
let content3 = r#"```bash
echo hello
```
{:.wrap #my-code .highlight}"#;
let ctx = LintContext::new(content3, rumdl_lib::config::MarkdownFlavor::Standard, None);
assert!(rule.check(&ctx).unwrap().is_empty());
}
#[test]
fn test_kramdown_no_blank_after_attribute() {
let rule = MD031BlanksAroundFences::default();
let content = r#"```bash
echo hello
```
{:.wrap}
Some text immediately after"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Should auto-detect Kramdown attributes");
}
#[test]
fn test_normal_code_blocks_still_checked() {
let rule = MD031BlanksAroundFences::default();
let content = r#"# Title
```bash
echo hello
```
Some text immediately after"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(
result.len(),
1,
"Should still flag missing blank line for normal code blocks"
);
}
#[test]
fn test_fix_preserves_kramdown_attributes() {
let rule = MD031BlanksAroundFences::default();
let content = r#"Text before
```bash
echo hello
```
{:.wrap}
Text after"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
let expected = r#"Text before
```bash
echo hello
```
{:.wrap}
Text after"#;
assert_eq!(fixed, expected);
}