fix/reflow_inner: return none if no reflow occurred
@@ -69,9 +69,12 @@ fn reflow_inner<'s>(
// iterations above add a newline add the end, we have to remove it
let replacement = replacement.trim_end_matches("\n").to_string();
-
+ if replacement == s {
+ None
+ } else {
Some(replacement)
}
+}
/// Reflow the documenation such that a maximum colomn constraint is met.
#[allow(unused)]
@@ -249,9 +252,15 @@ mod tests {
indentation,
$n,
chunk.variant()
- ).expect("Inner reflow works. qed");
+ );
- assert_eq!(replacement, $expected);
+ if let Some(repl) = replacement {
+ assert_eq!(repl, $expected);
+ } else {
+ for line in CONTENT.lines() {
+ assert!(line.len() < $n);
+ }
+ }
};
($line:literal => $expected:literal) => {
verify_reflow_inner!([$line] => $expected);
@@ -271,6 +280,18 @@ test our rewrapping algorithm.",
Smart, isn't it? Lorem ipsum and some more blanket text without any meaning"#);
}
+ #[test]
+ fn reflow_inner_not_required() {
+ verify_reflow_inner!(80 break ["This module contains documentation."] =>
+ r#" This module contains documentation."#);
+ {
+ verify_reflow_inner!(39 break ["This module contains documentation",
+ "which is split two lines"] =>
+ r#" This module contains documentation
+ which is split two lines"#);
+ }
+ }
+
macro_rules! reflow {
([ $( $line:literal ),+ $(,)?] => $expected:literal) => {
reflow!(80usize break [ $( $line ),+ ] => $expected );
