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
5 changed files with 30 additions and 1 deletions
+22 -1
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 @@ fn auto_detects_and_applies_native_newlines() {
);
}
}
#[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);
}
}
@@ -0,0 +1,2 @@
// rustfmt-newline_style: Unix
// Foo
@@ -0,0 +1,2 @@
// rustfmt-newline_style: Windows
// Foo
@@ -0,0 +1,2 @@
// rustfmt-newline_style: Unix
// Foo
@@ -0,0 +1,2 @@
// rustfmt-newline_style: Windows
// Foo