use rumdl_lib::lint_context::LintContext;
use rumdl_lib::rule::Rule;
use rumdl_lib::rules::MD028NoBlanksBlockquote;
#[test]
fn test_md028_valid() {
let rule = MD028NoBlanksBlockquote;
let content = "> Quote\n> Another line\n\n> New quote\n> Another line\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result[0].line, 3);
}
#[test]
fn test_md028_lines_with_marker_are_valid() {
let rule = MD028NoBlanksBlockquote;
let content = "> Quote\n> Another line\n>\n> Still same quote\n> Another line\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Lines with > marker should not be flagged");
}
#[test]
fn test_md028_invalid_blank_line() {
let rule = MD028NoBlanksBlockquote;
let content = "> Quote\n> Another line\n\n> Still same quote\n> Another line\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result[0].line, 3);
}
#[test]
fn test_md028_multiple_blanks() {
let rule = MD028NoBlanksBlockquote;
let content = "> Quote\n> Another line\n\n\n> Still same quote\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 2);
assert_eq!(result[0].line, 3);
assert_eq!(result[1].line, 4);
}
#[test]
fn test_md028_fix() {
let rule = MD028NoBlanksBlockquote;
let content = "> Quote\n> Another line\n\n> Still same quote\n> Another line\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.fix(&ctx).unwrap();
assert_eq!(
result,
"> Quote\n> Another line\n>\n> Still same quote\n> Another line\n"
);
}
#[test]
fn test_md028_nested_blockquotes_with_marker() {
let rule = MD028NoBlanksBlockquote;
let content = "> Outer quote\n>> Nested quote\n>>\n>> Still nested\n> Back to outer\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(result.is_empty(), "Lines with >> marker should not be flagged");
}
#[test]
fn test_md028_nested_blockquotes_blank() {
let rule = MD028NoBlanksBlockquote;
let content = "> Outer quote\n>> Nested quote\n\n>> Still nested\n> Back to outer\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result[0].line, 3);
let fixed = rule.fix(&ctx).unwrap();
let fixed_ctx = LintContext::new(&fixed, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed_result = rule.check(&fixed_ctx).unwrap();
assert!(fixed_result.is_empty());
assert_eq!(
fixed,
"> Outer quote\n>> Nested quote\n>>\n>> Still nested\n> Back to outer\n"
);
}
#[test]
fn test_md028_indented_blockquotes() {
let rule = MD028NoBlanksBlockquote;
let content = " > Indented quote\n > Another line\n\n > Still same quote\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1);
assert_eq!(result[0].line, 3);
let fixed = rule.fix(&ctx).unwrap();
let fixed_ctx = LintContext::new(&fixed, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed_result = rule.check(&fixed_ctx).unwrap();
assert!(fixed_result.is_empty());
assert_eq!(
fixed,
" > Indented quote\n > Another line\n >\n > Still same quote\n"
);
}
#[test]
fn test_md028_multi_blockquotes() {
let rule = MD028NoBlanksBlockquote;
let content = "> First quote\n> Another line\n\n> Second quote\n> Another line\n\n> Still second quote\n";
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 2);
assert_eq!(result[0].line, 3);
assert_eq!(result[1].line, 6);
let fixed = rule.fix(&ctx).unwrap();
let fixed_ctx = LintContext::new(&fixed, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed_result = rule.check(&fixed_ctx).unwrap();
assert!(fixed_result.is_empty());
assert_eq!(
fixed,
"> First quote\n> Another line\n>\n> Second quote\n> Another line\n>\n> Still second quote\n"
);
}