From 5eea30ca7a15a513fdc99a065efdfb2f43354658 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sun, 8 Apr 2018 22:17:52 +0200 Subject: [PATCH] lib: add minimal test for #129 --- README.md | 2 ++ src/lib.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 07b390bd..83ff31d3 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ Issues closed: * Fixed [#99][issue-99]: Word broken even though it would fit on line. * Fixed [#107][issue-107]: Automatic hyphenation is off by one. * Fixed [#122][issue-122]: Take newlines into account when wrapping. +* Fixed [#129][issue-129]: Panic on string with em-dash. ### Version 0.9.0 — October 5th, 2017 @@ -335,4 +336,5 @@ Contributions will be accepted under the same license. [issue-101]: https://github.com/mgeisler/textwrap/issues/101 [issue-107]: https://github.com/mgeisler/textwrap/issues/107 [issue-122]: https://github.com/mgeisler/textwrap/issues/122 +[issue-129]: https://github.com/mgeisler/textwrap/issues/129 [mit]: LICENSE diff --git a/src/lib.rs b/src/lib.rs index 7f610ae6..dc08f215 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1007,6 +1007,13 @@ mod tests { vec!["aaabbbccc", "x", "yyyzzzwww"]); } + #[test] + fn issue_129() { + // The dash is an em-dash which takes up four bytes. We used + // to panic since we tried to index into the character. + assert_eq!(wrap("x – x", 1), vec!["x", "–", "x"]); + } + #[test] fn wide_character_handling() { assert_eq!(wrap("Hello, World!", 15), vec!["Hello, World!"]);