use rumdl_lib::lint_context::LintContext;
use rumdl_lib::rule::Rule;
use rumdl_lib::rules::MD029OrderedListPrefix;
#[test]
fn test_md029_fix_with_2_space_code_blocks() {
let rule = MD029OrderedListPrefix::default();
let content = r#"# Title
1. Test 1
```sh
sudo dnf install ...
```
2. Test 2
3. Test 3
```sh
cargo install ...
```
4. Test 4
```sh
sudo dnf install ...
```
5. Test 5
```sh
sudo dnf install ...
```"#;
let expected = content;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(
fixed, expected,
"No changes - each list is correctly numbered from its CommonMark start value"
);
}
#[test]
fn test_md029_fix_with_4_space_code_blocks() {
let rule = MD029OrderedListPrefix::default();
let content = r#"# Title
1. Test 1
```sh
sudo dnf install ...
```
2. Test 2
3. Test 3
```sh
cargo install ...
```
4. Test 4"#;
let expected = content;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(
fixed, expected,
"MD029 fix should not change numbering when code blocks are properly indented"
);
}
#[test]
fn test_md029_fix_matches_check() {
let rule = MD029OrderedListPrefix::default();
let content = r#"1. First item
```
code block with 2 spaces
```
2. Second item
3. Third item"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let warnings = rule.check(&ctx).unwrap();
assert!(
warnings.is_empty(),
"No warnings - both lists are correctly numbered from their start values"
);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(
fixed, content,
"Fix should not change content when there are no warnings"
);
}
#[test]
fn test_md029_fix_preserves_content() {
let rule = MD029OrderedListPrefix::default();
let content = r#"1. First item with some text
```python
def hello():
print("world")
```
2. Second item with more text
3. Third item with even more text"#;
let ctx = LintContext::new(content, rumdl_lib::config::MarkdownFlavor::Standard, None);
let fixed = rule.fix(&ctx).unwrap();
assert_eq!(
fixed, content,
"Fix should not change content when there are no warnings"
);
}