From 6aa47f5ddb3facd12632972bc765ae6918091496 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sun, 13 Jul 2025 23:26:54 +0100 Subject: [PATCH 1/4] Add wrapping tests for list items --- tests/integration.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/integration.rs b/tests/integration.rs index bdbea78e..c8be2466 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -674,6 +674,39 @@ fn test_wrap_list_item() { } } +#[test] +fn test_wrap_bullet_with_inline_code() { + let input = vec![ + "- `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." + .to_string(), + ]; + let output = process_stream(&input); + assert_eq!(output.len(), 3); + assert!(output[0].starts_with("- ")); + assert!(output[1].starts_with(" ")); + assert!(output[2].starts_with(" ")); + assert!(output.iter().all(|l| l.len() <= 80)); +} + +#[test] +fn test_wrap_numbered_with_inline_code() { + let input = vec![ + "1. `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." + .to_string(), + ]; + let output = process_stream(&input); + assert_eq!(output.len(), 3); + assert!(output[0].starts_with("1. ")); + for line in output.iter().skip(1) { + assert!(line.starts_with(" ")); + } + assert!(output.iter().all(|l| l.len() <= 80)); +} + #[test] /// Verifies that short list items are not wrapped or altered by the stream processing logic. /// From 66e13ac309414d1d1f057c8ed0724ce832dff5b3 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sun, 13 Jul 2025 23:37:04 +0100 Subject: [PATCH 2/4] Refactor wrapping tests --- tests/common/mod.rs | 14 ++++++++++++++ tests/integration.rs | 34 +++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0e7518ff..9cbe30b2 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -9,3 +9,17 @@ 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_eq!(output.len(), expected); + assert!(output.first().map_or(false, |l| l.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)); + } +} diff --git a/tests/integration.rs b/tests/integration.rs index c8be2466..8ac44bec 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -664,14 +664,7 @@ 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); } #[test] @@ -683,11 +676,7 @@ fn test_wrap_bullet_with_inline_code() { .to_string(), ]; let output = process_stream(&input); - assert_eq!(output.len(), 3); - assert!(output[0].starts_with("- ")); - assert!(output[1].starts_with(" ")); - assert!(output[2].starts_with(" ")); - assert!(output.iter().all(|l| l.len() <= 80)); + common::assert_wrapped_list_item(&output, "- ", 3); } #[test] @@ -699,12 +688,19 @@ fn test_wrap_numbered_with_inline_code() { .to_string(), ]; let output = process_stream(&input); - assert_eq!(output.len(), 3); - assert!(output[0].starts_with("1. ")); - for line in output.iter().skip(1) { - assert!(line.starts_with(" ")); - } - assert!(output.iter().all(|l| l.len() <= 80)); + common::assert_wrapped_list_item(&output, "1. ", 3); +} + +#[test] +fn test_wrap_numbered_multi_digit() { + let input = vec![ + "10. `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." + .to_string(), + ]; + let output = process_stream(&input); + common::assert_wrapped_list_item(&output, "10. ", 3); } #[test] From 88b53449f913f71cf981beb0dc3d1b62fc81daf1 Mon Sep 17 00:00:00 2001 From: Leynos Date: Sun, 13 Jul 2025 23:53:40 +0100 Subject: [PATCH 3/4] Refactor list wrapping tests --- tests/common/mod.rs | 2 ++ tests/integration.rs | 40 +++++++++------------------------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9cbe30b2..9e09694b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -15,6 +15,8 @@ macro_rules! lines_vec { /// 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().map_or(false, |l| l.starts_with(prefix))); assert!(output.iter().all(|l| l.len() <= 80)); diff --git a/tests/integration.rs b/tests/integration.rs index 8ac44bec..e03854ea 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -667,40 +667,18 @@ fn test_wrap_list_item() { common::assert_wrapped_list_item(&output, "- ", 2); } -#[test] -fn test_wrap_bullet_with_inline_code() { - let input = vec![ - "- `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." - .to_string(), - ]; - let output = process_stream(&input); - common::assert_wrapped_list_item(&output, "- ", 3); -} - -#[test] -fn test_wrap_numbered_with_inline_code() { - let input = vec![ - "1. `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." - .to_string(), - ]; - let output = process_stream(&input); - common::assert_wrapped_list_item(&output, "1. ", 3); -} - -#[test] -fn test_wrap_numbered_multi_digit() { - let input = vec![ - "10. `script`: A multi-line script declared with the YAML `|` block style. The entire \ +#[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." - .to_string(), - ]; + )]; let output = process_stream(&input); - common::assert_wrapped_list_item(&output, "10. ", 3); + common::assert_wrapped_list_item(&output, prefix, expected); } #[test] From b20a33eea758506fa58c76a231df838fc97f6dfe Mon Sep 17 00:00:00 2001 From: Leynos Date: Mon, 14 Jul 2025 00:42:36 +0100 Subject: [PATCH 4/4] Fix clippy lint in helper --- tests/common/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9e09694b..0903d971 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -18,7 +18,7 @@ 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().map_or(false, |l| l.starts_with(prefix))); + 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) {