Skip to content
Merged
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
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,28 @@ mod tests {
);
}

#[test]
fn wrap_text_does_not_insert_spaces_in_hyphenated_words() {
let input = vec![
concat!(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt ",
"elit-sed fermentum congue. Vivamus dictum nulla sed consectetur ",
"volutpat."
)
.to_string(),
];
let wrapped = wrap_text(&input, 80);
assert_eq!(
wrapped,
vec![
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt"
.to_string(),
"elit-sed fermentum congue. Vivamus dictum nulla sed consectetur volutpat."
.to_string(),
]
);
}
Comment on lines +762 to +782
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Deduplicate hyphen-wrap tests via #[rstest] parameterisation

The new test exercises exactly the same invariant as wrap_text_preserves_hyphenated_words, only with a different input string and wrap width. The coding guidelines mandate replacing duplicated tests with #[rstest(...)] parameterised cases. Merge both checks into a single fixture that varies:

  • the input string
  • the wrap width
  • the expected vector

This removes repetition while preserving coverage and keeps the test module concise.

Example skeleton:

-#[test]
-fn wrap_text_preserves_hyphenated_words() { … }
-
-#[test]
-fn wrap_text_does_not_insert_spaces_in_hyphenated_words() { … }
+#[rstest(
+    (input, width, expected),
+    case(
+        "A word that is very-long-word indeed",
+        20,
+        vec![
+            "A word that is",
+            "very-long-word",
+            "indeed"
+        ]
+    ),
+    case(
+        concat!(
+            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt ",
+            "elit-sed fermentum congue. Vivamus dictum nulla sed consectetur volutpat."
+        ),
+        80,
+        vec![
+            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt",
+            "elit-sed fermentum congue. Vivamus dictum nulla sed consectetur volutpat."
+        ]
+    )
+)]
+fn wrap_text_preserves_hyphenated_words(input: &str, width: usize, expected: Vec<&str>) {
+    let wrapped = wrap_text(&[input.to_string()], width);
+    assert_eq!(
+        wrapped,
+        expected.into_iter().map(str::to_string).collect::<Vec<_>>()
+    );
+}

Enforce cargo fmt and cargo clippy after refactor to keep the build clean.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/lib.rs around lines 762 to 782, the test
wrap_text_does_not_insert_spaces_in_hyphenated_words duplicates the logic of
wrap_text_preserves_hyphenated_words with different inputs. Refactor by merging
both tests into a single parameterized test using #[rstest] that takes input
string, wrap width, and expected output vector as parameters. This will remove
duplication while maintaining test coverage. After refactoring, run cargo fmt
and cargo clippy to ensure code style and linting compliance.


#[test]
fn wrap_text_preserves_code_spans() {
let input = vec![
Expand Down