diff options
| author | bors <bors@rust-lang.org> | 2015-11-03 13:34:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-03 13:34:09 +0000 |
| commit | c143ae7764a4bedc61c6c9d86803af940f813a58 (patch) | |
| tree | 7ea07c4ab8e7dc5436f9c906ed41a0ff73362b7e | |
| parent | f18c90516326673a2b2a9ed01d271d1d338154f7 (diff) | |
| parent | a9cbf6c1c1a93817c0e316a9b17439525f7d6a70 (diff) | |
| download | rust-c143ae7764a4bedc61c6c9d86803af940f813a58.tar.gz rust-c143ae7764a4bedc61c6c9d86803af940f813a58.zip | |
Auto merge of #29495 - meqif:fix_unindent_tabs, r=steveklabnik
A line may be indented with either spaces or tabs, but not a mix of both. If there is a mix of tabs and spaces, only the kind that occurs first is counted. This addresses issue #29268.
| -rw-r--r-- | src/librustdoc/passes.rs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 1957f1efa47..a09ca95dcea 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -331,18 +331,18 @@ pub fn unindent(s: &str) -> String { min_indent } else { saw_first_line = true; - let mut spaces = 0; + let mut whitespace = 0; line.chars().all(|char| { - // Only comparing against space because I wouldn't - // know what to do with mixed whitespace chars - if char == ' ' { - spaces += 1; + // Compare against either space or tab, ignoring whether they + // are mixed or not + if char == ' ' || char == '\t' { + whitespace += 1; true } else { false } }); - cmp::min(min_indent, spaces) + cmp::min(min_indent, whitespace) } }); @@ -407,4 +407,22 @@ mod unindent_tests { let r = unindent(&s); assert_eq!(r, "line1\n\n line2"); } + + #[test] + fn should_unindent_tabs() { + let s = "\tline1\n\tline2".to_string(); + let r = unindent(&s); + assert_eq!(r, "line1\nline2"); + } + + #[test] + fn should_trim_mixed_indentation() { + let s = "\t line1\n\t line2".to_string(); + let r = unindent(&s); + assert_eq!(r, "line1\nline2"); + + let s = " \tline1\n \tline2".to_string(); + let r = unindent(&s); + assert_eq!(r, "line1\nline2"); + } } |
