\n> -\n> bad\n", vec![4]),
("> - \n> ===\n> text\n> bad\n", vec![4]),
("> - a \\| b | c\n> --- | ---\n> outside\n> bad\n", vec![4]),
("> - a | b\n> --- | ---\n> c | d\n> outside\n> bad\n", vec![5]),
("> - a | b\n> --- | ---\n> text\n> x\n", vec![]),
("> - a\n> -\n> text\n> bad\n", vec![4]),
("> - a\n> 2. b\n> c\n", vec![]),
("> text\n> 1. is a list\n> c\n", vec![]),
("> -\n> text\n", vec![]),
// A fence outside the quote ends it, and a tab pads a marker to the next
// multiple of four columns.
("> - a\n```\ncode\n```\n> text\n", vec![5]),
("> 1.\ta\n>\n> b\n", vec![3]),
("> 1.\ta\n>\n> b\n", vec![]),
("> - a\n>\t- b\n", vec![]),
] {
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let lines: Vec = rule.check(&ctx).unwrap().iter().map(|w| w.line).collect();
assert_eq!(lines, expected, "{content:?}");
}
}
#[test]
fn test_list_items_default_skips_continuation() {
// Continuation line inside a blockquoted list is skipped by default
let rule = MD027MultipleSpacesBlockquote::default();
let content = "# Test\n\n> - first item\n> more list-y text\n";
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(
result.is_empty(),
"Default should skip both list-item and continuation, got {result:?}"
);
}
#[test]
fn test_plain_blockquote_text_flagged_in_both_modes() {
let content = "# Test\n\n> Plain blockquote text with extra space.\n";
for cfg in [MD027Config { list_items: false }, MD027Config { list_items: true }] {
let rule = MD027MultipleSpacesBlockquote::with_config(cfg.clone());
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(
result.len(),
1,
"Plain blockquote text with extra spaces should always be flagged (cfg={cfg:?}), got {result:?}"
);
}
}
#[test]
fn test_md027_config_kebab_case_parses() {
let toml_str = r#"
list-items = true
"#;
let config: MD027Config = toml::from_str(toml_str).unwrap();
assert!(config.list_items);
}
#[test]
fn test_md027_config_snake_case_alias_parses() {
let toml_str = r#"
list_items = true
"#;
let config: MD027Config = toml::from_str(toml_str).unwrap();
assert!(config.list_items);
}
#[test]
fn test_md027_config_default_is_false() {
let cfg = MD027Config::default();
assert!(!cfg.list_items, "rumdl default for list_items should be false");
}
#[test]
fn test_md027_html_comment() {
let rule = MD027MultipleSpacesBlockquote::default();
let content = "";
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert!(
result.is_empty(),
"MD027 should not flag blockquotes inside HTML comments: {result:?}"
);
}
#[test]
fn test_lazy_line_indent_that_changes_the_parse_is_reported_but_not_fixed() {
let rule = MD027MultipleSpacesBlockquote::default();
// Four or more columns past the marker, the line continues the
// paragraph. One space would make it a break, heading, list or fence.
for content in [
"> o\n> ---\n",
"> o\n> ===\n",
"> o\n> # x\n",
"> o\n> - x\n",
"> o\n> ```\n",
"> > o\n> > ---\n",
] {
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let warnings = rule.check(&ctx).unwrap();
assert!(!warnings.is_empty(), "{content:?} must still be reported");
assert!(
warnings.iter().all(|w| w.fix.is_none()),
"{content:?} must carry no fix: {warnings:?}"
);
assert_eq!(rule.fix(&ctx).unwrap(), content, "{content:?}");
}
}
#[test]
fn test_lazy_line_indent_on_plain_prose_is_still_fixed() {
let rule = MD027MultipleSpacesBlockquote::default();
let content = "> o\n> more text\n> and more\n";
let ctx = LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
assert_eq!(rule.fix(&ctx).unwrap(), "> o\n> more text\n> and more\n");
}
}