Remove the redundant borrowed line wrapping helper (#33870)

## What changed

Remove `word_wrap_lines_borrowed` and use the general `word_wrap_lines` API for
borrowed line slices. Drop the duplicate helper-specific tests while retaining
coverage of borrowed iterator wrapping through the general API.

GitOrigin-RevId: aa55a6180705a676bf82ea66c9ba0fe15d00a5fe
This commit is contained in:
jif
2026-07-17 16:39:16 +00:00
committed by copyberry
parent 771d9d7d26
commit f57467275c
+1 -48
View File
@@ -1007,29 +1007,6 @@ where
out
}
#[allow(dead_code)]
pub(crate) fn word_wrap_lines_borrowed<'a, I, O>(lines: I, width_or_options: O) -> Vec<Line<'a>>
where
I: IntoIterator<Item = &'a Line<'a>>,
O: Into<RtOptions<'a>>,
{
let base_opts: RtOptions<'a> = width_or_options.into();
let mut out: Vec<Line<'a>> = Vec::new();
let mut first = true;
for line in lines.into_iter() {
let opts = if first {
base_opts.clone()
} else {
base_opts
.clone()
.initial_indent(base_opts.subsequent_indent.clone())
};
out.extend(word_wrap_line(line, opts));
first = false;
}
out
}
fn slice_line_spans<'a>(
original: &'a Line<'a>,
span_bounds: &[(Range<usize>, ratatui::style::Style)],
@@ -1253,30 +1230,6 @@ mod tests {
assert_eq!(rendered, vec!["hello", "world!"]);
}
#[test]
fn wrap_lines_borrowed_applies_initial_indent_only_once() {
let opts = RtOptions::new(/*width*/ 8)
.initial_indent(Line::from("- "))
.subsequent_indent(Line::from(" "));
let lines = [Line::from("hello world"), Line::from("foo bar baz")];
let out = word_wrap_lines_borrowed(lines.iter(), opts);
let rendered: Vec<String> = out.iter().map(concat_line).collect();
assert!(rendered.first().unwrap().starts_with("- "));
for r in rendered.iter().skip(1) {
assert!(r.starts_with(" "));
}
}
#[test]
fn wrap_lines_borrowed_without_indents_is_concat_of_single_wraps() {
let lines = [Line::from("hello"), Line::from("world!")];
let out = word_wrap_lines_borrowed(lines.iter(), /*width_or_options*/ 10);
let rendered: Vec<String> = out.iter().map(concat_line).collect();
assert_eq!(rendered, vec!["hello", "world!"]);
}
#[test]
fn wrap_lines_accepts_borrowed_iterators() {
let lines = [Line::from("hello world"), Line::from("foo bar baz")];
@@ -1307,7 +1260,7 @@ mod tests {
let line = Line::from(sample);
let lines = [line];
// Force small width to exercise wrapping at spaces.
let wrapped = word_wrap_lines_borrowed(&lines, /*width_or_options*/ 40);
let wrapped = word_wrap_lines(&lines, /*width_or_options*/ 40);
let joined: String = wrapped.iter().map(ToString::to_string).join("\n");
assert_eq!(
joined,