Preserve standalone carriage returns on windows also

This commit is contained in:
Ruben Schmidmeister 2019-04-24 20:52:43 +02:00
parent 2e77f2bca7
commit 19bd1a44ce
No known key found for this signature in database
GPG key ID: 29387B5A7AAF863F
5 changed files with 30 additions and 1 deletions

View file

@ -67,7 +67,6 @@ fn convert_to_windows_newlines(formatted_text: &String) -> String {
const WINDOWS_NEWLINE: &str = "\r\n";
match c {
LINE_FEED => transformed.push_str(WINDOWS_NEWLINE),
CARRIAGE_RETURN => continue,
c => transformed.push(c),
}
}
@ -155,4 +154,26 @@ mod tests {
);
}
}
#[test]
fn preserves_standalone_carriage_returns_when_applying_windows_newlines() {
let formatted_text = "One\nTwo\nThree\rDrei";
let raw_input_text = "One\nTwo\nThree\rDrei";
let mut out = String::from(formatted_text);
apply_newline_style(NewlineStyle::Windows, &mut out, raw_input_text);
assert_eq!("One\r\nTwo\r\nThree\rDrei", &out);
}
#[test]
fn preserves_standalone_carriage_returns_when_applying_unix_newlines() {
let formatted_text = "One\nTwo\nThree\rDrei";
let raw_input_text = "One\nTwo\nThree\rDrei";
let mut out = String::from(formatted_text);
apply_newline_style(NewlineStyle::Unix, &mut out, raw_input_text);
assert_eq!("One\nTwo\nThree\rDrei", &out);
}
}

View file

@ -0,0 +1,2 @@
// rustfmt-newline_style: Unix
// Foo Bar

View file

@ -0,0 +1,2 @@
// rustfmt-newline_style: Windows
// Foo Bar

View file

@ -0,0 +1,2 @@
// rustfmt-newline_style: Unix
// Foo Bar

View file

@ -0,0 +1,2 @@
// rustfmt-newline_style: Windows
// Foo Bar