mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 03:14:11 +00:00
Split apply with auto detection tests into separate fns
This commit is contained in:
parent
0f1d5760ba
commit
2e77f2bca7
@ -116,47 +116,43 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_newline_style_auto_apply() {
|
||||
let auto = NewlineStyle::Auto;
|
||||
|
||||
fn auto_detects_and_applies_unix_newlines() {
|
||||
let formatted_text = "One\nTwo\nThree";
|
||||
let raw_input_text = "One\nTwo\nThree";
|
||||
|
||||
let mut out = String::from(formatted_text);
|
||||
apply_newline_style(auto, &mut out, raw_input_text);
|
||||
apply_newline_style(NewlineStyle::Auto, &mut out, raw_input_text);
|
||||
assert_eq!("One\nTwo\nThree", &out, "auto should detect 'lf'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_detects_and_applies_windows_newlines() {
|
||||
let formatted_text = "One\nTwo\nThree";
|
||||
let raw_input_text = "One\r\nTwo\r\nThree";
|
||||
|
||||
let mut out = String::from(formatted_text);
|
||||
apply_newline_style(auto, &mut out, raw_input_text);
|
||||
apply_newline_style(NewlineStyle::Auto, &mut out, raw_input_text);
|
||||
assert_eq!("One\r\nTwo\r\nThree", &out, "auto should detect 'crlf'");
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let formatted_text = "One\nTwo\nThree";
|
||||
let raw_input_text = "One Two Three";
|
||||
#[test]
|
||||
fn auto_detects_and_applies_native_newlines() {
|
||||
let formatted_text = "One\nTwo\nThree";
|
||||
let raw_input_text = "One Two Three";
|
||||
|
||||
let mut out = String::from(formatted_text);
|
||||
apply_newline_style(auto, &mut out, raw_input_text);
|
||||
let mut out = String::from(formatted_text);
|
||||
apply_newline_style(NewlineStyle::Auto, &mut out, raw_input_text);
|
||||
|
||||
if cfg!(windows) {
|
||||
assert_eq!(
|
||||
"One\r\nTwo\r\nThree", &out,
|
||||
"auto-native-windows should detect 'crlf'"
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
"One\nTwo\nThree", &out,
|
||||
"auto-native-unix should detect 'lf'"
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let formatted_text = "One\nTwo\nThree";
|
||||
let raw_input_text = "One Two Three";
|
||||
|
||||
let mut out = String::from(formatted_text);
|
||||
apply_newline_style(auto, &mut out, raw_input_text);
|
||||
assert_eq!(
|
||||
"One\r\nTwo\r\nThree", &out,
|
||||
"auto-native-windows should detect 'crlf'"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user