Fixed bug with word wrapping when a word is longer than a line.

This commit is contained in:
Nathan Vegdahl 2018-01-01 13:25:06 -08:00
parent dbb640b330
commit 54a16c6383

View File

@ -267,6 +267,7 @@ where
self.indent_found = true;
}
if self.pos.1 > 0 {
if self.f.maintain_indent {
self.pos = (
self.pos.0 + self.f.single_line_height(),
@ -279,6 +280,7 @@ where
);
}
}
}
self.word_i = 0;
}
@ -356,6 +358,58 @@ mod tests {
);
}
#[test]
fn dimensions_3() {
// 55 graphemes long
let text = "税マイミ文末\
\
\
\
西\
\
\
\
\
";
let mut f = ConsoleLineFormatter::new(4);
f.wrap_type = WrapType::CharWrap(0);
f.maintain_indent = false;
f.wrap_additional_indent = 0;
f.set_wrap_width(12);
assert_eq!(
f.dimensions(UnicodeSegmentation::graphemes(text, true)),
(10, 12)
);
}
#[test]
fn dimensions_4() {
// 55 graphemes long
let text = "税マイミ文末\
\
\
\
西\
\
\
\
\
";
let mut f = ConsoleLineFormatter::new(4);
f.wrap_type = WrapType::WordWrap(0);
f.maintain_indent = false;
f.wrap_additional_indent = 0;
f.set_wrap_width(12);
assert_eq!(
f.dimensions(UnicodeSegmentation::graphemes(text, true)),
(10, 12)
);
}
#[test]
fn index_to_v2d_1() {
let text = "Hello there, stranger!"; // 22 graphemes long