Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,19 @@ macro_rules! lines_vec {
vec![$($line.to_string()),*]
};
}

/// Assert common wrapping expectations for list items.
///
/// Verifies the number of lines, prefix on the first line, length of all lines,
/// and indentation of continuation lines.
pub fn assert_wrapped_list_item(output: &[String], prefix: &str, expected: usize) {
assert!(expected > 0, "expected line count must be positive");
assert!(!output.is_empty(), "output slice is empty");
assert_eq!(output.len(), expected);
assert!(output.first().is_some_and(|line| line.starts_with(prefix)));
assert!(output.iter().all(|l| l.len() <= 80));
let indent = " ".repeat(prefix.len());
for line in output.iter().skip(1) {
assert!(line.starts_with(&indent));
}
}
23 changes: 15 additions & 8 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,21 @@ fn test_wrap_list_item() {
.to_string(),
];
let output = process_stream(&input);
assert!(output.len() > 1);
assert!(output[0].starts_with("- "));
for line in &output {
assert!(line.len() <= 80);
}
for line in output.iter().skip(1) {
assert!(line.starts_with(" "));
}
common::assert_wrapped_list_item(&output, "- ", 2);
}

#[rstest]
#[case("- ", 3)]
#[case("1. ", 3)]
#[case("10. ", 3)]
fn test_wrap_list_items_with_inline_code(#[case] prefix: &str, #[case] expected: usize) {
let input = vec![format!(
"{prefix}`script`: A multi-line script declared with the YAML `|` block style. The entire \
block is passed to an interpreter. If the first line begins with `#!`, Netsuke executes \
the script verbatim, respecting the shebang."
)];
let output = process_stream(&input);
common::assert_wrapped_list_item(&output, prefix, expected);
}

#[test]
Expand Down