diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/features/line_numbers.rs | 12 | ||||
-rw-r--r-- | src/features/side_by_side.rs | 12 | ||||
-rw-r--r-- | src/wrapping.rs | 18 |
4 files changed, 25 insertions, 21 deletions
diff --git a/src/config.rs b/src/config.rs index d89af7d5..4074551b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -623,6 +623,10 @@ pub fn delta_unreachable(message: &str) -> ! { } #[cfg(test)] +// Usual length of the header returned by `run_delta()`, often `skip()`-ed. +pub const HEADER_LEN: usize = 7; + +#[cfg(test)] pub mod tests { use crate::bat_utils::output::PagingMode; use crate::cli; diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 6d2e6168..f1ad146f 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -493,7 +493,7 @@ pub mod tests { "0 4", ]); let output = run_delta(TWO_MINUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!(strip_ansi_codes(line_1), " 1 ⋮ │a = 1"); assert_eq!(strip_ansi_codes(line_2), " 2 ⋮ │b = 23456"); @@ -517,7 +517,7 @@ pub mod tests { "0 4", ]); let output = run_delta(TWO_PLUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!(strip_ansi_codes(line_1), " ⋮ 1 │a = 1"); assert_eq!(strip_ansi_codes(line_2), " ⋮ 2 │b = 234567"); @@ -542,7 +542,7 @@ pub mod tests { ]); let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); let output = strip_ansi_codes(&output); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); assert_eq!(lines.next().unwrap(), " 1 ⋮ 1 │a = 1"); assert_eq!(lines.next().unwrap(), " 2 ⋮ │b = 2"); assert_eq!(lines.next().unwrap(), " ⋮ 2 │bb = 2"); @@ -567,7 +567,7 @@ pub mod tests { ]); let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); let output = strip_ansi_codes(&output); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); assert_eq!(lines.next().unwrap(), " 1 1 ⋮ 1 │a = 1"); assert_eq!(lines.next().unwrap(), " 2 2 ⋮ │b = 2"); assert_eq!(lines.next().unwrap(), " ⋮ 2 │bb = 2"); @@ -578,7 +578,7 @@ pub mod tests { let config = make_config_from_args(&["--line-numbers"]); let output = run_delta(FIVE_DIGIT_LINE_NUMBER_DIFF, &config); let output = strip_ansi_codes(&output); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); assert_eq!(lines.next().unwrap(), "10000⋮10000│a = 1"); assert_eq!(lines.next().unwrap(), "10001⋮ │b = 2"); assert_eq!(lines.next().unwrap(), " ⋮10001│bb = 2"); @@ -589,7 +589,7 @@ pub mod tests { let config = make_config_from_args(&["--line-numbers"]); let output = run_delta(UNEQUAL_DIGIT_DIFF, &config); let output = strip_ansi_codes(&output); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); assert_eq!(lines.next().unwrap(), "10000⋮9999 │a = 1"); assert_eq!(lines.next().unwrap(), "10001⋮ │b = 2"); assert_eq!(lines.next().unwrap(), " ⋮10000│bb = 2"); diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs index cc31249d..42924623 100644 --- a/src/features/side_by_side.rs +++ b/src/features/side_by_side.rs @@ -489,7 +489,7 @@ pub mod tests { fn test_two_minus_lines() { let config = make_config_from_args(&["--side-by-side", "--width", "40"]); let output = run_delta(TWO_MINUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!("│ 1 │a = 1 │ │", strip_ansi_codes(line_1)); assert_eq!("│ 2 │b = 23456 │ │", strip_ansi_codes(line_2)); @@ -507,7 +507,7 @@ pub mod tests { ]); config.truncation_symbol = ">".into(); let output = run_delta(TWO_MINUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!("│ 1 │a = 1 │ │", strip_ansi_codes(line_1)); assert_eq!("│ 2 │b = 234>│ │", strip_ansi_codes(line_2)); @@ -517,7 +517,7 @@ pub mod tests { fn test_two_plus_lines() { let config = make_config_from_args(&["--side-by-side", "--width", "40"]); let output = run_delta(TWO_PLUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); let sac = strip_ansi_codes; // alias to help with `cargo fmt`-ing: assert_eq!("│ │ │ 1 │a = 1 ", sac(line_1)); @@ -537,7 +537,7 @@ pub mod tests { config.truncation_symbol = ">".into(); let output = run_delta(TWO_PLUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!("│ │ │ 1 │a = 1 ", strip_ansi_codes(line_1)); assert_eq!("│ │ │ 2 │b = 2345>", strip_ansi_codes(line_2)); @@ -547,7 +547,7 @@ pub mod tests { fn test_two_plus_lines_exact_fit() { let config = make_config_from_args(&["--side-by-side", "--width", "32"]); let output = run_delta(TWO_PLUS_LINES_DIFF, &config); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let (line_1, line_2) = (lines.next().unwrap(), lines.next().unwrap()); assert_eq!("│ │ │ 1 │a = 1 ", strip_ansi_codes(line_1)); assert_eq!("│ │ │ 2 │b = 234567", strip_ansi_codes(line_2)); @@ -558,7 +558,7 @@ pub mod tests { let config = make_config_from_args(&["--side-by-side", "--width", "40"]); let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); let output = strip_ansi_codes(&output); - let mut lines = output.lines().skip(7); + let mut lines = output.lines().skip(crate::config::HEADER_LEN); let mut lnu = move || lines.next().unwrap(); // for cargo fmt assert_eq!("│ 1 │a = 1 │ 1 │a = 1", lnu()); assert_eq!("│ 2 │b = 2 │ 2 │bb = 2 ", lnu()); diff --git a/src/wrapping.rs b/src/wrapping.rs index d183afe1..9c4489eb 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -915,7 +915,7 @@ index 223ca50..e69de29 100644 let output = run_delta(HUNK_ZERO_DIFF, &config); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│L│abcdefghijklm+ │RRRR│abcdefghijklm+", "│L│nopqrstuvwxzy+ │RRRR│nopqrstuvwxzy+", @@ -942,7 +942,7 @@ index 223ca50..e69de29 100644 let output = run_delta(HUNK_ZERO_LARGE_LINENUMBERS_DIFF, &config); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│LLL│abcde+ │WW 10 +- 101999 WW│abcde+", "│LLL│fghij+ │WW +- WW│fghij+", @@ -966,7 +966,7 @@ index 223ca50..e69de29 100644 let output = run_delta(HUNK_MP_DIFF, &config); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 4 │ abcdefghijklmn+│ 15 │ abcdefghijklmn+", "│ │ opqrstuvwxzy 0+│ │ opqrstuvwxzy 0+", @@ -996,7 +996,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2<│ 1 │.........1.........2+", "│ │ >....│ │.........3.........4+", @@ -1014,7 +1014,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2+│ 1 │.........1.........2<", "│ │.........3.........4+│ │ >....", @@ -1038,7 +1038,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2....│ 1 │.........1.........2...+", "│ │ │ │......3.........4......+", @@ -1056,7 +1056,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2...+│ 1 │.........1.........2....", "│ │......3.........4......+│ │", @@ -1087,7 +1087,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2.... │ 1 │.........1.........2.........+", "│ │ │ │3.........4.........5........+", @@ -1106,7 +1106,7 @@ index 223ca50..e69de29 100644 &config, ); let output = strip_ansi_codes(&output); - let lines: Vec<_> = output.lines().skip(7).collect(); + let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect(); let expected = vec![ "│ 1 │.........1.........2.... │ 1 │.........1.........2.........+", "│ │ │ │3.........4.........5........>", |