Preserve standalone carriage returns on windows also
This commit is contained in:
parent
2e77f2bca7
commit
19bd1a44ce
5 changed files with 30 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
tests/source/preserves_carriage_return_for_unix.rs
Normal file
2
tests/source/preserves_carriage_return_for_unix.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// rustfmt-newline_style: Unix
|
||||
// Foo
Bar
|
||||
2
tests/source/preserves_carriage_return_for_windows.rs
Normal file
2
tests/source/preserves_carriage_return_for_windows.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// rustfmt-newline_style: Windows
|
||||
// Foo
Bar
|
||||
2
tests/target/preserves_carriage_return_for_unix.rs
Normal file
2
tests/target/preserves_carriage_return_for_unix.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// rustfmt-newline_style: Unix
|
||||
// Foo
Bar
|
||||
2
tests/target/preserves_carriage_return_for_windows.rs
Normal file
2
tests/target/preserves_carriage_return_for_windows.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// rustfmt-newline_style: Windows
|
||||
// Foo
Bar
|
||||
Loading…
Add table
Add a link
Reference in a new issue