Skip to content

Commit

Permalink
Fix fill fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoohey31 committed Nov 29, 2022
1 parent 112dc33 commit e9d18ce
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ where
{
let options = width_or_options.into();

if text.len() < options.width && !text.contains('\n') && options.initial_indent.is_empty() {
String::from(text.trim_end_matches(' '))
if text.len() < options.width
&& options.tab_width <= 1
&& !text.contains('\n')
&& options.initial_indent.is_empty()
{
String::from(text.trim_end_matches(&[' ', '\t']))
} else {
fill_slow_path(text, options)
}
Expand Down Expand Up @@ -215,6 +219,21 @@ mod tests {
);
}

#[test]
fn fill_tabs() {
let options = Options::new(10).tab_width(4);
assert_eq!(
fill("Hello\t there\t friends", options),
"Hello\nthere\nfriends"
);
}

#[test]
fn fill_tabs_prevent_fast_path() {
let options = Options::new(10).tab_width(4);
assert_eq!(fill("Hey\tworld", options), "Hey\nworld");
}

#[test]
fn break_words_line_breaks() {
assert_eq!(fill("ab\ncdefghijkl", 5), "ab\ncdefg\nhijkl");
Expand Down

0 comments on commit e9d18ce

Please sign in to comment.