#[cfg(test)]
mod tests {
use console::strip_ansi_codes;
use crate::tests::ansi_test_utils::ansi_test_utils;
use crate::tests::integration_test_utils::integration_test_utils;
#[test]
fn test_added_file() {
let options = integration_test_utils::get_command_line_options();
let (output, _) = integration_test_utils::run_delta(ADDED_FILE_INPUT, options);
let output = strip_ansi_codes(&output);
assert!(output.contains("\nadded: a.py\n"));
if false {
// TODO: hline width
assert_eq!(output, ADDED_FILE_EXPECTED_OUTPUT);
}
}
#[test]
#[ignore] // #128
fn test_added_empty_file() {
let options = integration_test_utils::get_command_line_options();
let (output, _) = integration_test_utils::run_delta(ADDED_EMPTY_FILE, options);
let output = strip_ansi_codes(&output);
assert!(output.contains("\nadded: file\n"));
}
#[test]
fn test_added_file_directory_path_containing_space() {
let options = integration_test_utils::get_command_line_options();
let (output, _) =
integration_test_utils::run_delta(ADDED_FILES_DIRECTORY_PATH_CONTAINING_SPACE, options);
let output = strip_ansi_codes(&output);
assert!(output.contains("\nadded: with space/file1\n"));
assert!(output.contains("\nadded: nospace/file2\n"));
}
#[test]
fn test_renamed_file() {
let options = integration_test_utils::get_command_line_options();
let (output, _) = integration_test_utils::run_delta(RENAMED_FILE_INPUT, options);
let output = strip_ansi_codes(&output);
assert!(output.contains("\nrenamed: a.py ⟶ b.py\n"));
}
#[test]
fn test_recognized_file_type() {
// In addition to the background color, the code has language syntax highlighting.
let options = integration_test_utils::get_command_line_options();
let (output, config) = integration_test_utils::get_line_of_code_from_delta(
&ADDED_FILE_INPUT,
12,
" class X:",
options,
);
ansi_test_utils::assert_has_color_other_than_plus_color(&output, &config);
}
#[test]
fn test_unrecognized_file_type_with_theme() {
// In addition to the background color, the code has the foreground color using the default
// .txt syntax under the theme.
let options = integration_test_utils::get_command_line_options();
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let (output, config) =
integration_test_utils::get_line_of_code_from_delta(&input, 12, " class X:", options);
ansi_test_utils::assert_has_color_other_than_plus_color(&output, &config);
}
#[test]
fn test_unrecognized_file_type_no_theme() {
// The code has the background color only. (Since there is no theme, the code has no
// foreground ansi color codes.)
let mut options = integration_test_utils::get_command_line_options();
options.theme = Some("none".to_string());
let input = ADDED_FILE_INPUT.replace("a.py", "a");
let (output, config) =
integration_test_utils::get_line_of_code_from_delta(&input, 12, " class X:", options);
ansi_test_utils::assert_has_plus_color_only(&output, &config);
}
#[test]
fn test_diff_unified_two_files() {
let options = integration_test_utils::get_command_line_options();
let (output, _) = integration_test_utils::run_delta(DIFF_UNIFIED_TWO_FILES,