Split apply with auto detection tests into separate fns

This commit is contained in:
Ruben Schmidmeister 2019-04-24 20:28:14 +02:00
parent 0f1d5760ba
commit 2e77f2bca7
No known key found for this signature in database
GPG Key ID: 29387B5A7AAF863F

View File

@ -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'"
);
}
}
}