fix: allow final word to be wrapped in wrap_help

Before, inserting a newline did not move the prev_space index forward.
This meant that the next word was measured incorrectly since the
length was measured back to the word before the newly inserted
linebreak.

Fixes #828.
This commit is contained in:
Martin Geisler 2017-01-29 11:46:23 +01:00
parent 563a539a8e
commit 564c5f0f17
2 changed files with 15 additions and 1 deletions

View file

@ -960,8 +960,21 @@ fn wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) {
debugln!("Help::wrap_help:iter: Char at {}: {:?}", j, &help[j..j+1]);
help.remove(j);
help.insert(j, '\n');
prev_space = idx;
}
} else {
sdebugln!("No");
}
}
#[cfg(test)]
mod test {
use super::wrap_help;
#[test]
fn wrap_help_last_word() {
let mut help = String::from("foo bar baz");
wrap_help(&mut help, 3, 5);
assert_eq!(help, "foo\nbar\nbaz");
}
}

View file

@ -159,7 +159,8 @@ FLAGS:
information
-V, --version
Prints
version information";
version
information";
static OLD_NEWLINE_CHARS: &'static str = "ctest 0.1