mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
Preserve standalone carriage returns on windows also
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user