Skip to content

Commit

Permalink
fix: allow final word to be wrapped in wrap_help
Browse files Browse the repository at this point in the history
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 clap-rs#828.
  • Loading branch information
mgeisler committed Jan 29, 2017
1 parent c41f2e7 commit 49ad0ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

#[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");
}
}
3 changes: 2 additions & 1 deletion tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ FLAGS:
information
-V, --version
Prints
version information";
version
information";

static OLD_NEWLINE_CHARS: &'static str = "ctest 0.1
Expand Down

0 comments on commit 49ad0ac

Please sign in to comment.