mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 03:44:24 +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]
|
#[test]
|
||||||
fn test_newline_style_auto_apply() {
|
fn auto_detects_and_applies_unix_newlines() {
|
||||||
let auto = NewlineStyle::Auto;
|
|
||||||
|
|
||||||
let formatted_text = "One\nTwo\nThree";
|
let formatted_text = "One\nTwo\nThree";
|
||||||
let raw_input_text = "One\nTwo\nThree";
|
let raw_input_text = "One\nTwo\nThree";
|
||||||
|
|
||||||
let mut out = String::from(formatted_text);
|
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'");
|
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 formatted_text = "One\nTwo\nThree";
|
||||||
let raw_input_text = "One\r\nTwo\r\nThree";
|
let raw_input_text = "One\r\nTwo\r\nThree";
|
||||||
|
|
||||||
let mut out = String::from(formatted_text);
|
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'");
|
assert_eq!("One\r\nTwo\r\nThree", &out, "auto should detect 'crlf'");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[test]
|
||||||
{
|
fn auto_detects_and_applies_native_newlines() {
|
||||||
let formatted_text = "One\nTwo\nThree";
|
let formatted_text = "One\nTwo\nThree";
|
||||||
let raw_input_text = "One Two Three";
|
let raw_input_text = "One Two Three";
|
||||||
|
|
||||||
let mut out = String::from(formatted_text);
|
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);
|
||||||
|
|
||||||
|
if cfg!(windows) {
|
||||||
|
assert_eq!(
|
||||||
|
"One\r\nTwo\r\nThree", &out,
|
||||||
|
"auto-native-windows should detect 'crlf'"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"One\nTwo\nThree", &out,
|
"One\nTwo\nThree", &out,
|
||||||
"auto-native-unix should detect 'lf'"
|
"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