use rumdl_lib::utils::code_block_utils::CodeBlockUtils;
#[test]
fn test_commonmark_example_108_list_continuation_precedence() {
let content = " - foo\n\n bar";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Example 108: list continuation should take precedence over code block interpretation"
);
}
#[test]
fn test_commonmark_example_270_code_block_in_list() {
let content = "- foo\n\n bar";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"Example 270: 6 spaces in list (continuation + 4) should be code block"
);
assert!(
content[blocks[0].0..blocks[0].1].contains("bar"),
"Code block should contain 'bar'"
);
}
#[test]
fn test_commonmark_example_273_multiple_code_blocks_in_list() {
let content = "1. indented code\n\n paragraph\n\n more code";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(blocks.len(), 2, "Example 273: two code blocks detected (in list)");
}
#[test]
fn test_commonmark_example_257_insufficient_indent() {
let content = " - one\n\n two";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"Example 257: 5-space indent after list ends is treated as code block"
);
}
#[test]
fn test_multidigit_ordered_list_not_code_block() {
let content = "Paragraph\n\n 10. Item one\n 11. Item two\n\n code";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"Multi-digit ordered lists followed by 4-space indented line should create code block"
);
}
#[test]
fn test_ordered_list_single_space() {
let content = "1. First\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Ordered list continuation with single space should not be code block"
);
}
#[test]
fn test_ordered_list_multiple_spaces() {
let content = "1. First\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"5 spaces after ordered list marker creates code block (verified with cmark)"
);
}
#[test]
fn test_code_block_in_ordered_list() {
let content = "1. Item\n\n code";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"7 spaces in ordered list (continuation at 3 + 4) should be code block"
);
}
#[test]
fn test_unordered_list_asterisk() {
let content = "* Item\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Unordered list with * should not mark continuation as code block"
);
}
#[test]
fn test_unordered_list_plus() {
let content = "+ Item\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Unordered list with + should not mark continuation as code block"
);
}
#[test]
fn test_list_extra_spaces_after_marker() {
let content = "- Item with extra spaces\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"List with 4 spaces after marker should calculate continuation indent correctly"
);
}
#[test]
fn test_document_level_code_block_4_spaces() {
let content = "Paragraph\n\n code block";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"4 spaces at document level after blank should be code block"
);
}
#[test]
fn test_list_then_document_code_block() {
let content = "- Item\n\n continuation\n\nCode after list\n\n code block";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
1,
"Should detect document-level code block after list ends"
);
assert!(
content[blocks[0].0..blocks[0].1].contains("code block"),
"Code block should be the last part"
);
}
#[test]
fn test_three_spaces_not_code_block() {
let content = "Paragraph\n\n not code";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(blocks.len(), 0, "3 spaces should not be code block");
}
#[test]
fn test_ordered_list_closing_paren() {
let content = "1) Item\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(blocks.len(), 0, "Ordered list with ) delimiter should work correctly");
}
#[test]
fn test_two_digit_ordered_list() {
let content = "12. Item\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Two-digit ordered list should calculate continuation correctly"
);
}
#[test]
fn test_three_digit_ordered_list() {
let content = "123. Item\n\n continuation";
let blocks = CodeBlockUtils::detect_code_blocks(content);
assert_eq!(
blocks.len(),
0,
"Three-digit ordered list should calculate continuation correctly"
);
}