Lines Matching full:options
5 use crate::{fill, LineEnding, Options};
29 /// [`Options::initial_indent`] and the prefix (if any) of the the
30 /// other lines is returned in [`Options::subsequent_indent`].
32 /// Line ending is returned in [`Options::line_ending`]. If line ending
51 /// let (text, options) = unfill("\
58 /// assert_eq!(options.initial_indent, "* ");
59 /// assert_eq!(options.subsequent_indent, " ");
60 /// assert_eq!(options.line_ending, LineEnding::LF);
62 pub fn unfill(text: &str) -> (String, Options<'_>) { in unfill()
65 let mut options = Options::new(0); in unfill() localVariable
67 options.width = std::cmp::max(options.width, display_width(line)); in unfill()
72 options.initial_indent = prefix; in unfill()
74 options.subsequent_indent = prefix; in unfill()
76 for ((idx, x), y) in prefix.char_indices().zip(options.subsequent_indent.chars()) { in unfill()
78 options.subsequent_indent = &prefix[..idx]; in unfill()
82 if prefix.len() < options.subsequent_indent.len() { in unfill()
83 options.subsequent_indent = prefix; in unfill()
93 unfilled.push_str(&line[options.initial_indent.len()..]); in unfill()
96 unfilled.push_str(&line[options.subsequent_indent.len()..]); in unfill()
112 options.line_ending = detected_line_ending.unwrap_or(LineEnding::LF); in unfill()
113 (unfilled, options) in unfill()
122 /// specify other options as well — except for
123 /// [`Options::initial_indent`] and [`Options::subsequent_indent`],
171 Opt: Into<Options<'a>>, in refill()
174 let (text, options) = unfill(filled_text); in refill()
176 let stripped = text.strip_suffix(options.line_ending.as_str()); in refill()
179 new_options.initial_indent = options.initial_indent; in refill()
180 new_options.subsequent_indent = options.subsequent_indent; in refill()
196 let (text, options) = unfill("foo\nbar"); in unfill_simple()
198 assert_eq!(options.width, 3); in unfill_simple()
199 assert_eq!(options.line_ending, LineEnding::LF); in unfill_simple()
204 let (text, options) = unfill("foo bar"); in unfill_no_new_line()
206 assert_eq!(options.width, 7); in unfill_no_new_line()
207 assert_eq!(options.line_ending, LineEnding::LF); in unfill_no_new_line()
212 let (text, options) = unfill("foo\r\nbar"); in unfill_simple_crlf()
214 assert_eq!(options.width, 3); in unfill_simple_crlf()
215 assert_eq!(options.line_ending, LineEnding::CRLF); in unfill_simple_crlf()
220 let (text, options) = unfill("foo\r\nbar\nbaz"); in unfill_mixed_new_lines()
222 assert_eq!(options.width, 3); in unfill_mixed_new_lines()
223 assert_eq!(options.line_ending, LineEnding::LF); in unfill_mixed_new_lines()
228 let (text, options) = unfill("foo\n*\n/"); in test_unfill_consecutive_different_prefix()
230 assert_eq!(options.width, 3); in test_unfill_consecutive_different_prefix()
231 assert_eq!(options.line_ending, LineEnding::LF); in test_unfill_consecutive_different_prefix()
236 let (text, options) = unfill("foo\nbar\n\n\n"); in unfill_trailing_newlines()
238 assert_eq!(options.width, 3); in unfill_trailing_newlines()
243 let (text, options) = unfill("foo\r\nbar\n\r\n\n"); in unfill_mixed_trailing_newlines()
245 assert_eq!(options.width, 3); in unfill_mixed_trailing_newlines()
246 assert_eq!(options.line_ending, LineEnding::LF); in unfill_mixed_trailing_newlines()
251 let (text, options) = unfill("foo bar\r\n"); in unfill_trailing_crlf()
253 assert_eq!(options.width, 7); in unfill_trailing_crlf()
254 assert_eq!(options.line_ending, LineEnding::CRLF); in unfill_trailing_crlf()
259 let (text, options) = unfill(" foo\nbar\nbaz"); in unfill_initial_indent()
261 assert_eq!(options.width, 5); in unfill_initial_indent()
262 assert_eq!(options.initial_indent, " "); in unfill_initial_indent()
267 let (text, options) = unfill(" foo\n bar\n baz"); in unfill_differing_indents()
269 assert_eq!(options.width, 7); in unfill_differing_indents()
270 assert_eq!(options.initial_indent, " "); in unfill_differing_indents()
271 assert_eq!(options.subsequent_indent, " "); in unfill_differing_indents()
276 let (text, options) = unfill("* foo\n bar\n baz"); in unfill_list_item()
278 assert_eq!(options.width, 5); in unfill_list_item()
279 assert_eq!(options.initial_indent, "* "); in unfill_list_item()
280 assert_eq!(options.subsequent_indent, " "); in unfill_list_item()
285 let (text, options) = unfill(" // foo bar\n // baz\n // quux"); in unfill_multiple_char_prefix()
287 assert_eq!(options.width, 14); in unfill_multiple_char_prefix()
288 assert_eq!(options.initial_indent, " // "); in unfill_multiple_char_prefix()
289 assert_eq!(options.subsequent_indent, " // "); in unfill_multiple_char_prefix()
294 let (text, options) = unfill("> foo\n> bar\n> baz"); in unfill_block_quote()
296 assert_eq!(options.width, 5); in unfill_block_quote()
297 assert_eq!(options.initial_indent, "> "); in unfill_block_quote()
298 assert_eq!(options.subsequent_indent, "> "); in unfill_block_quote()
305 let (text, options) = unfill("######\nfoo"); in unfill_only_prefixes_issue_466()
307 assert_eq!(options.width, 6); in unfill_only_prefixes_issue_466()
308 assert_eq!(options.initial_indent, "######"); in unfill_only_prefixes_issue_466()
309 assert_eq!(options.subsequent_indent, ""); in unfill_only_prefixes_issue_466()
317 let (text, options) = unfill("foo\n##\n\n\r"); in unfill_trailing_newlines_issue_466()
320 assert_eq!(options.width, 3); in unfill_trailing_newlines_issue_466()
321 assert_eq!(options.initial_indent, ""); in unfill_trailing_newlines_issue_466()
322 assert_eq!(options.subsequent_indent, ""); in unfill_trailing_newlines_issue_466()
332 let options = Options::new(5).line_ending(LineEnding::CRLF); in refill_convert_lf_to_crlf() localVariable
333 assert_eq!(refill("foo\nbar\n", options), "foo\r\nbar\r\n",); in refill_convert_lf_to_crlf()
338 let options = Options::new(5).line_ending(LineEnding::LF); in refill_convert_crlf_to_lf() localVariable
339 assert_eq!(refill("foo\r\nbar\r\n", options), "foo\nbar\n",); in refill_convert_crlf_to_lf()
344 let options = Options::new(5).line_ending(LineEnding::CRLF); in refill_convert_mixed_newlines() localVariable
345 assert_eq!(refill("foo\r\nbar\n", options), "foo\r\nbar\r\n",); in refill_convert_mixed_newlines()