Debian Codegraph @

src/utils/helpwrap.rs

raw symbols SCIP
1 #![allow(clippy::comparison_to_empty)] // no_indent != "", instead of !no_indent.is_empty()
2
3 use craterust-analyzer cargo git-delta 0.19.2 crate/::ansirust-analyzer cargo git-delta 0.19.2 ansi/::measure_text_widthrust-analyzer cargo git-delta 0.19.2 ansi/measure_text_width().;
4
5 /// Wrap `text` at spaces ('` `') to fit into `width`. If `indent_with` is non-empty, indent
6 /// each line with this string. If a line from `text` starts with `no_indent`, do not indent.
7 /// If a line starts with `no_wrap`, do not wrap (empty `no_indent`/`no_wrap` have no effect).
8 /// If both "magic prefix" markers are used, `no_indent` must be first.
9 /// Takes unicode and ANSI into account when calculating width, but won't wrap ANSI correctly.
10 /// Removes trailing spaces. Leading spaces or enumerations with '- ' continue the indentation on
11 /// the wrapped line.
12 /// Example:
13 /// ```
14 /// let wrapped = wrap("ab cd ef\n!NI!123\n|AB CD EF GH\n!NI!|123 456 789", 7, "_", "!NI!", "|");
15 /// assert_eq!(wrapped, "\
16 /// _ab cd\n\
17 /// _ef\n\
18 /// 123\n\
19 /// _AB CD EF GH\n\
20 /// 123 456 789\n\
21 /// ");
22 /// ```
23 pub fn wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(text: &str, width: usize, indent_with: &str, no_indent: &str, no_wrap: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
24 let mut result = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(text.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
25 let indent_len = measure_text_widthrust-analyzer cargo git-delta 0.19.2 ansi/measure_text_width().(indent_with);
26
27 for line in text.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
28 let line = line.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(' ');
29
30 let (line, indent) =
31 if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line), true) = (line.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(no_indent), no_indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."") {
32 (line, "")
33 } else {
34 result.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(indent_with);
35 (line, indent_with)
36 };
37
38 if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line), true) = (line.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().(no_wrap), no_wrap rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()."") {
39 result.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(line);
40 } else {
41 // `"foo bar end".split_inclusive(' ')` => `["foo ", "bar ", " ", " ", "end"]`
42 let mut wordit = line.split_inclusiverust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_inclusive().(' ');
43 let mut curr_len = indent_len;
44
45 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(word) = wordit.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitInclusive<'a, P>`][Iterator]next().() {
46 result.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(word);
47 curr_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().measure_text_widthrust-analyzer cargo git-delta 0.19.2 ansi/measure_text_width().(word);
48 }
49
50 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut word) = wordit.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitInclusive<'a, P>`][Iterator]next().() {
51 let word_len = measure_text_widthrust-analyzer cargo git-delta 0.19.2 ansi/measure_text_width().(word);
52 if curr_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().word_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 && word.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(' ') {
53 // If just ' ' is over the limit, let the next word trigger the overflow.
54 } else if curr_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().word_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().width {
55 // Remove any trailing whitespace:
56 let pos = result.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(' ').lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
57 result.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(pos);
58
59 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
60
61 // Do not count spaces, skip until next proper word is found.
62 if word rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()." " {
63 for nextword in wordit.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().() {
64 word = nextword;
65 if word rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne()." " {
66 break;
67 }
68 }
69 }
70
71 // Re-calculates indent for each wrapped line. Could be done only once, maybe
72 // after an early return which just uses .len() (works for fullwidth chars).
73
74 // If line started with spaces, indent by that much again.
75 let (indent, space_pos) =
76 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(space_prefix_len) = line.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c: char| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().' ') {
77 (
78 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", indent, " ".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(space_prefix_len)),
79 space_prefix_len,
80 )
81 } else {
82 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(false, "line.trim_end_matches() missing?");
83 (indent.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), 0)
84 };
85
86 // If line started with '- ', treat it as a bullet point and increase indentation
87 let indent = if line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().space_pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("- ") {
88 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", indent, " ")
89 } else {
90 indent
91 };
92
93 result.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&indent);
94 curr_len = measure_text_widthrust-analyzer cargo git-delta 0.19.2 ansi/measure_text_width().(&indent);
95 }
96 curr_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().word_len;
97 result.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(word);
98 }
99 }
100 let pos = result.trim_end_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end_matches().(' ').lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
101 result.truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(pos);
102 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n');
103 }
104
105 #[cfg(test)]
106 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().result.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("no-sanity") {
107 // sanity check
108 let stripped_input = text
109 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(" ", "")
110 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("\n", "")
111 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(no_wrap, "")
112 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(no_indent, "");
113 let stripped_output = result
114 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(" ", "")
115 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("\n", "")
116 .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(indent_with, "");
117 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stripped_input, stripped_output);
118 }
119
120 result
121 }
122
123 #[cfg(test)]
124 mod testrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/ {
125 use superrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/::*;
126 use instarust-analyzer cargo insta 1.39.0 crate/::assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!;
127
128 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
129 fn simple_ascii_can_not_splitrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_can_not_split().() {
130 let input = "000 123456789 abcdefghijklmnopqrstuvwxyz ok";
131 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 5, "", "", "");
132 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
133 000
134 123456789
135 abcdefghijklmnopqrstuvwxyz
136 ok
137 "###);
138 }
139
140 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
141 fn simple_ascii_just_whitespacerust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_just_whitespace().() {
142 let input = " \n \n \n \n \n \n";
143 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 3, "__", "", "");
144 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
145 __
146 __
147 __
148 __
149 __
150 __
151 "###);
152 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 3, "", "", "");
153 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "\n\n\n\n\n\n");
154 }
155
156 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
157 fn simple_ascii_can_not_split_plus_whitespacerust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_can_not_split_plus_whitespace().() {
158 let input = "000 123456789 abcdefghijklmnopqrstuvwxyz ok";
159 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 5, "", "", "");
160 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
161 000
162 123456789
163 abcdefghijklmnopqrstuvwxyz
164 ok
165 "###);
166 }
167
168 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
169 fn simple_ascii_keep_leading_input_indentrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_keep_leading_input_indent().() {
170 let input = "abc\n Def ghi jkl mno pqr stuv xyz\n Abc def ghijklm\nok";
171 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "_", "", "");
172 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
173 _abc
174 _ Def ghi
175 _ jkl mno
176 _ pqr
177 _ stuv
178 _ xyz
179 _ Abc
180 _ def
181 _ ghijklm
182 _ok
183 "###);
184 }
185
186 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
187 fn simple_ascii_indent_and_bullet_pointsrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_indent_and_bullet_points().() {
188 let input = "- ABC ABC abc\n def ghi - jkl\n - 1 22 3 4 55 6 7 8 9\n - 1 22 3 4 55 6 7 8 9\n!- 0 0 0 0 0 0 0 \n";
189 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "", "!", "");
190 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
191 - ABC ABC
192 abc
193 def ghi
194 - jkl
195 - 1 22 3
196 4 55 6
197 7 8 9
198 - 1 22
199 3 4
200 55 6
201 7 8
202 9
203 - 0 0 0 0
204 0 0 0
205 "###);
206 }
207
208 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
209 fn simple_ascii_all_overlong_after_indentrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_all_overlong_after_indent().() {
210 let input = "0000 1111 2222";
211 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 5, "__", "", "");
212 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
213 __0000
214 __1111
215 __2222
216 "###);
217 }
218
219 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
220 fn simple_ascii_one_linerust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_one_line().() {
221 let input = "123 456 789 abc def ghi jkl mno pqr stu vwx yz";
222 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "", "");
223 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
224 __123 456
225 __789 abc
226 __def ghi
227 __jkl mno
228 __pqr stu
229 __vwx yz
230 "###);
231 }
232
233 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
234 fn simple_ascii_trailing_spacerust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_trailing_space().() {
235 let input = "123 \n\n \n 456 \n a b \n\n";
236 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, " ", "", "");
237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, " 123\n\n\n 456\n a\n b\n\n");
238 }
239
240 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
241 fn simple_ascii_two_linesrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_two_lines().() {
242 let input = "123 456 789 abc def\nghi jkl mno pqr stu vwx yz\n1234 567 89 876 54321\n";
243 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "", "");
244 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
245 __123 456
246 __789 abc
247 __def
248 __ghi jkl
249 __mno pqr
250 __stu vwx
251 __yz
252 __1234 567
253 __89 876
254 __54321
255 "###);
256 }
257
258 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
259 fn simple_ascii_no_indentrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_no_indent().() {
260 let input = "123 456 789\n!!abc def ghi jkl mno pqr\nstu vwx yz\n\n";
261 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "!!", "");
262 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
263 __123 456
264 __789
265 abc def
266 ghi jkl
267 mno pqr
268 __stu vwx
269 __yz
270 __
271 "###);
272 }
273
274 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
275 fn simple_ascii_no_wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_no_wrap().() {
276 let input = "123 456 789\n|abc def ghi jkl mno pqr\nstu vwx yz\n|W\nA B C D E F G H I\n";
277 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "!!", "|");
278 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
279 __123 456
280 __789
281 __abc def ghi jkl mno pqr
282 __stu vwx
283 __yz
284 __W
285 __A B C D
286 __E F G H
287 __I
288 "###);
289 }
290
291 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
292 fn simple_ascii_no_bothrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_no_both().() {
293 let input = "123 456 789\n!!|abc def ghi jkl mno pqr\nstu vwx yz\n|W\nA B C D E F G H I\n";
294 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "!!", "|");
295 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
296 __123 456
297 __789
298 abc def ghi jkl mno pqr
299 __stu vwx
300 __yz
301 __W
302 __A B C D
303 __E F G H
304 __I
305 "###);
306 }
307
308 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
309 fn simple_ascii_no_both_wrong_orderrust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_no_both_wrong_order().() {
310 let input = "!!|abc def ghi jkl\n|!!ABC DEF GHI JKL + no-sanity\n";
311 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 7, "__", "!!", "|");
312 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
313 abc def ghi jkl
314 __!!ABC DEF GHI JKL + no-sanity
315 "###);
316 let wrapped = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(
317 "ab cd ef\n!NI!123\n|AB CD EF GH\n!NI!|123 456 789",
318 6,
319 "_",
320 "!NI!",
321 "|",
322 );
323 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(wrapped, @r###"
324 _ab cd
325 _ef
326 123
327 _AB CD EF GH
328 123 456 789
329 "###);
330 }
331
332 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
333 fn simple_ascii_much_whitespacerust-analyzer cargo git-delta 0.19.2 utils/helpwrap/test/simple_ascii_much_whitespace().() {
334 let input = "123 456 789\nabc def ghi jkl mno pqr \nstu vwx yz";
335 let result = wraprust-analyzer cargo git-delta 0.19.2 utils/helpwrap/wrap().(input, 10, "__", "!!", "|");
336 assert_snapshotrust-analyzer cargo insta 1.39.0 macros/assert_snapshot!!(result, @r###"
337 __123
338 __456
339 __789
340 __abc
341 __def ghi
342 __jkl mno
343 __pqr
344 __stu
345 __vwx yz
346 "###);
347 }
348 }