Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word broken even though it would fit on line #99

Closed
mgeisler opened this issue Sep 30, 2017 · 2 comments
Closed

Word broken even though it would fit on line #99

mgeisler opened this issue Sep 30, 2017 · 2 comments
Labels

Comments

@mgeisler
Copy link
Owner

This test case fails, even though the "qqqqqqqqq" word is only 9 characters long:

    #[test]
    fn test_very_ragged() {
        // Example of inputs that produce very ragged output with the
        // greedy algorithm.
        assert_eq!(wrap("a b c d e f g h i j k l m n o p qqqqqqqqq", 10),
                   vec!["a b c d e", "f g h i j", "k l m n o", "p", "qqqqqqqqq"]);
    }

It fails with

---- tests::test_very_ragged stdout ----
	thread 'tests::test_very_ragged' panicked at 'assertion failed: `(left == right)`
  left: `["a b c d e", "f g h i j", "k l m n o", "p qqqqqqqq", "q"]`,
 right: `["a b c d e", "f g h i j", "k l m n o", "p", "qqqqqqqqq"]`', src/lib.rs:1080:8
@mgeisler mgeisler added the bug label Sep 30, 2017
@mgeisler
Copy link
Owner Author

Bisecting shows that this was introduced back in version 0.7.0 in commit 4313d58 (Wrapper::wrap: return Vec<Cow> instead of Vec).

@mgeisler
Copy link
Owner Author

mgeisler commented Dec 17, 2017

The above test case can be simplified to just

#[test]
fn test_very_ragged() {
    assert_eq!(textwrap::wrap("aaabbbccc x yyyzzzwww", 9),
               vec!["aaabbbccc", "x", "yyyzzzwww"]);
}

mgeisler added a commit that referenced this issue Dec 17, 2017
We did not reset the in_whitespace flag immediately when seeing a
non-whitespace character. This meant that single character words could
be split incorrectly.

Fixes #99.
mgeisler added a commit that referenced this issue Dec 17, 2017
We did not reset the in_whitespace flag immediately when seeing a
non-whitespace character. This meant that single character words could
be split incorrectly.

Fixes #99.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant