summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2021-12-06 22:12:08 +0100
committerDan Davison <dandavison7@gmail.com>2021-12-07 19:18:23 -0500
commitd7ef078acbd97d45448237617b03d516969430f4 (patch)
treec2c30ce046598324a7a5a9913bf51182a5f61b37
parent47b073d224757217de468063904d1c8342e290d1 (diff)
Add DeltaTest to speed up adding and fixing tests
Using a syntax similar to the builder pattern: `DeltaTest::with([config options]).with_input(DIFF).expect(lines)` plus `.explain_ansi()` to pretty-print ansi codes and `.inspect()` to print the to-be-tested output. Rewrite a few tests using it and add ansi tests for --line-fill-method=<spaces|ansi>
-rw-r--r--src/features/line_numbers.rs34
-rw-r--r--src/features/side_by_side.rs91
-rw-r--r--src/tests/integration_test_utils.rs219
-rw-r--r--src/wrapping.rs210
4 files changed, 393 insertions, 161 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index 59218f75..47017960 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -322,7 +322,7 @@ pub mod tests {
use crate::ansi::strip_ansi_codes;
use crate::features::side_by_side::ansifill::ODD_PAD_CHAR;
use crate::format::FormatStringData;
- use crate::tests::integration_test_utils::{make_config_from_args, run_delta};
+ use crate::tests::integration_test_utils::{make_config_from_args, run_delta, DeltaTest};
use super::*;
@@ -630,7 +630,7 @@ pub mod tests {
#[test]
fn test_two_minus_lines() {
- let config = make_config_from_args(&[
+ DeltaTest::with(&[
"--line-numbers",
"--line-numbers-left-format",
"{nm:^4}⋮",
@@ -644,17 +644,19 @@ pub mod tests {
"0 3",
"--line-numbers-plus-style",
"0 4",
- ]);
- let output = run_delta(TWO_MINUS_LINES_DIFF, &config);
- 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");
+ ])
+ .with_input(TWO_MINUS_LINES_DIFF)
+ .expect(
+ r#"
+ #indent_mark
+ 1 ⋮ │a = 1
+ 2 ⋮ │b = 23456"#,
+ );
}
#[test]
fn test_two_plus_lines() {
- let config = make_config_from_args(&[
+ DeltaTest::with(&[
"--line-numbers",
"--line-numbers-left-format",
"{nm:^4}⋮",
@@ -668,12 +670,14 @@ pub mod tests {
"0 3",
"--line-numbers-plus-style",
"0 4",
- ]);
- let output = run_delta(TWO_PLUS_LINES_DIFF, &config);
- 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");
+ ])
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .expect(
+ r#"
+ #indent_mark
+ ⋮ 1 │a = 1
+ ⋮ 2 │b = 234567"#,
+ );
}
#[test]
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index 568142dc..890bc0b3 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -582,50 +582,79 @@ pub mod ansifill {
pub mod tests {
use crate::ansi::strip_ansi_codes;
use crate::features::line_numbers::tests::*;
- use crate::tests::integration_test_utils::{make_config_from_args, run_delta};
+ use crate::tests::integration_test_utils::{make_config_from_args, run_delta, DeltaTest};
#[test]
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(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));
+ DeltaTest::with(&["--side-by-side", "--width", "40"])
+ .with_input(TWO_MINUS_LINES_DIFF)
+ .expect(
+ r#"
+ │ 1 │a = 1 │ │
+ │ 2 │b = 23456 │ │"#,
+ );
}
#[test]
fn test_two_minus_lines_truncated() {
- let mut config = make_config_from_args(&[
+ DeltaTest::with(&[
"--side-by-side",
"--wrap-max-lines",
"0",
"--width",
"28",
"--line-fill-method=spaces",
- ]);
- config.truncation_symbol = ">".into();
- let output = run_delta(TWO_MINUS_LINES_DIFF, &config);
- 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));
+ ])
+ .set_cfg(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(TWO_MINUS_LINES_DIFF)
+ .expect(
+ r#"
+ │ 1 │a = 1 │ │
+ │ 2 │b = 234>│ │"#,
+ );
}
#[test]
fn test_two_plus_lines() {
- let config = make_config_from_args(&[
+ DeltaTest::with(&[
"--side-by-side",
"--width",
"41",
"--line-fill-method=spaces",
- ]);
- let output = run_delta(TWO_PLUS_LINES_DIFF, &config);
- 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));
- assert_eq!("│ │ │ 2 │b = 234567 ", sac(line_2));
+ ])
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .expect(
+ r#"
+ │ │ │ 1 │a = 1
+ │ │ │ 2 │b = 234567 "#,
+ );
+ }
+
+ #[test]
+ fn test_two_plus_lines_spaces_and_ansi() {
+ DeltaTest::with(&[
+ "--side-by-side",
+ "--width",
+ "41",
+ "--line-fill-method=spaces",
+ ])
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .explain_ansi()
+ .expect(r#"
+ (blue)│(88) (blue)│(normal) (blue)│(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal 22) (normal)
+ (blue)│(88) (blue)│(normal) (blue)│(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal 22) (normal)"#);
+
+ DeltaTest::with(&[
+ "--side-by-side",
+ "--width",
+ "41",
+ "--line-fill-method=ansi",
+ ])
+ .with_input(TWO_PLUS_LINES_DIFF)
+ .explain_ansi()
+ .expect(r#"
+ (blue)│(88) (blue)│(normal) (blue) │(28) 1 (blue)│(231 22)a (203)=(231) (141)1(normal)
+ (blue)│(88) (blue)│(normal) (blue) │(28) 2 (blue)│(231 22)b (203)=(231) (141)234567(normal)"#);
}
#[test]
@@ -661,17 +690,17 @@ pub mod tests {
#[test]
fn test_one_minus_one_plus_line() {
- let config = make_config_from_args(&[
+ DeltaTest::with(&[
"--side-by-side",
"--width",
"40",
"--line-fill-method=spaces",
- ]);
- let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config);
- let output = strip_ansi_codes(&output);
- 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());
+ ])
+ .with_input(ONE_MINUS_ONE_PLUS_LINE_DIFF)
+ .expect(
+ r#"
+ │ 1 │a = 1 │ 1 │a = 1
+ │ 2 │b = 2 │ 2 │bb = 2 "#,
+ );
}
}
diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs
index bdb28514..44dd3bee 100644
--- a/src/tests/integration_test_utils.rs
+++ b/src/tests/integration_test_utils.rs
@@ -88,6 +88,111 @@ pub fn get_line_of_code_from_delta(
line_of_code.to_string()
}
+// Given an `expected` block as a raw string like: `r#"
+// #indent_mark [optional]
+// line1"#;` // line 2 etc.
+// ignore the first newline and compare the following `lines()` to those produced
+// by `have`, `skip`-ping the first few. The leading spaces of the first line
+// are strippedfrom every following line (and verified) , unless the first line
+// marks the indentation level with `#indent_mark`.
+pub fn lines_match(expected: &str, have: &str, skip: Option<usize>) {
+ let mut exp = expected.lines().peekable();
+ assert!(exp.next() == Some(""), "first line must be empty");
+ let line1 = exp.peek().unwrap();
+ let indentation = line1.find(|c| c != ' ').unwrap_or(0);
+ let ignore_indent = &line1[indentation..] == "#indent_mark";
+ if ignore_indent {
+ let _indent_mark = exp.next();
+ }
+
+ let mut it = have.lines().skip(skip.unwrap_or(0));
+
+ for (i, expected) in exp.enumerate() {
+ if !ignore_indent {
+ let next_indentation = expected.find(|c| c != ' ').unwrap_or(0);
+ assert!(
+ indentation == next_indentation,
+ "The expected block has mixed indentation (use #indent_mark if that is on purpose)"
+ );
+ }
+ assert_eq!(
+ &expected[indentation..],
+ it.next().unwrap(),
+ "on line {} of input",
+ i + 1
+ );
+ }
+ assert_eq!(it.next(), None, "more input than expected");
+}
+
+pub struct DeltaTest {
+ config: config::Config,
+}
+
+impl DeltaTest {
+ pub fn with(args: &[&str]) -> Self {
+ Self {
+ config: make_config_from_args(args),
+ }
+ }
+
+ pub fn set_cfg<F>(mut self, f: F) -> Self
+ where
+ F: Fn(&mut config::Config),
+ {
+ f(&mut self.config);
+ self
+ }
+
+ pub fn with_config_and_input(config: &config::Config, input: &str) -> DeltaTestOutput {
+ DeltaTestOutput {
+ output: run_delta(input, &config),
+ explain_ansi_: false,
+ }
+ }
+
+ pub fn with_input(&self, input: &str) -> DeltaTestOutput {
+ DeltaTest::with_config_and_input(&self.config, input)
+ }
+}
+
+pub struct DeltaTestOutput {
+ output: String,
+ explain_ansi_: bool,
+}
+
+impl DeltaTestOutput {
+ pub fn inspect(self) -> Self {
+ if self.explain_ansi_ {
+ eprintln!("{}", ansi::explain_ansi(&self.output, true));
+ } else {
+ eprintln!("{}", &self.output);
+ }
+ self
+ }
+
+ pub fn explain_ansi(mut self) -> Self {
+ self.explain_ansi_ = true;
+ self
+ }
+
+ pub fn expect_skip(self, skip: usize, expected: &str) -> String {
+ let processed = if self.explain_ansi_ {
+ ansi::explain_ansi(&self.output, false)
+ } else {
+ ansi::strip_ansi_codes(&self.output)
+ };
+
+ lines_match(expected, &processed, Some(skip));
+
+ processed
+ }
+
+ pub fn expect(self, expected: &str) -> String {
+ self.expect_skip(crate::config::HEADER_LEN, expected)
+ }
+}
+
pub fn run_delta(input: &str, config: &config::Config) -> String {
let mut writer: Vec<u8> = Vec::new();
@@ -99,3 +204,117 @@ pub fn run_delta(input: &str, config: &config::Config) -> String {
.unwrap();
String::from_utf8(writer).unwrap()
}
+
+pub mod tests {
+ use super::*;
+
+ #[test]
+ fn test_lines_match_ok() {
+ let expected = r#"
+ one
+ two
+ three"#;
+ lines_match(expected, "one\ntwo\nthree", None);
+
+ let expected = r#"
+ #indent_mark
+ one
+ 2
+ three"#;
+ lines_match(expected, "one\n 2\nthree", None);
+
+ let expected = r#"
+ #indent_mark
+ 1
+ 2
+ 3"#;
+ lines_match(expected, " 1 \n 2 \n 3", None);
+
+ let expected = r#"
+ #indent_mark
+ 1
+ignored! 2
+ 3"#;
+ lines_match(expected, " 1 \n 2 \n 3", None);
+ let expected = "\none\ntwo\nthree";
+ lines_match(expected, "one\ntwo\nthree", None);
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_lines_match_no_nl() {
+ let expected = r#"bad
+ lines"#;
+ lines_match(expected, "bad\nlines", None);
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_lines_match_iter_not_consumed() {
+ let expected = r#"
+ one
+ two
+ three"#;
+ lines_match(expected, "one\ntwo\nthree\nFOUR", None);
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_lines_match_no_indent_mark_1() {
+ let expected = r#"
+ ok
+ wrong_indent
+ "#;
+ lines_match(expected, "ok", None);
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_lines_match_no_indent_mark_2() {
+ let expected = r#"
+ ok
+ wrong_indent
+ "#;
+ lines_match(expected, "ok", None);
+ }
+
+ #[test]
+ fn test_delta_test() {
+ let input = "@@ -1,1 +1,1 @@ fn foo() {\n-1\n+2\n";
+ DeltaTest::with(&["--raw"])
+ .set_cfg(|c| c.pager = None)
+ .set_cfg(|c| c.line_numbers = true)
+ .with_input(input)
+ .inspect()
+ .expect_skip(
+ 0,
+ r#"
+ #indent_mark
+ @@ -1,1 +1,1 @@ fn foo() {
+ 1 ⋮ │-1
+ ⋮ 1 │+2"#,
+ );
+
+ DeltaTest::with(&[])
+ .with_input(input)
+ .inspect()
+ .expect_skip(
+ 4,
+ r#"
+ 1
+ 2"#,
+ );
+
+ DeltaTest::with(&["--raw"])
+ .with_input(input)
+ .explain_ansi()
+ .inspect()
+ .expect_skip(
+ 0,
+ "\n\
+ (normal)@@ -1,1 +1,1 @@ fn foo() {\n\
+ (red)-1(normal)\n\
+ (green)+2(normal)",
+ );
+ }
+}
diff --git a/src/wrapping.rs b/src/wrapping.rs
index c66cdc87..1a652834 100644
--- a/src/wrapping.rs
+++ b/src/wrapping.rs
@@ -551,11 +551,10 @@ mod tests {
use super::wrap_line;
use super::WrapConfig;
- use crate::ansi::strip_ansi_codes;
use crate::config::Config;
use crate::paint::LineSections;
use crate::style::Style;
- use crate::tests::integration_test_utils::{make_config_from_args, run_delta};
+ use crate::tests::integration_test_utils::{make_config_from_args, DeltaTest};
lazy_static! {
static ref S1: Style = Style {
@@ -904,7 +903,7 @@ index 223ca50..e69de29 100644
#[test]
fn test_wrap_with_unequal_hunk_zero_width() {
- let mut config = make_config_from_args(&default_wrap_cfg_plus(&[
+ DeltaTest::with(&default_wrap_cfg_plus(&[
"--side-by-side",
"--line-numbers-left-format",
"│L│",
@@ -914,26 +913,23 @@ index 223ca50..e69de29 100644
"40",
"--line-fill-method",
"spaces",
- ]));
- config.truncation_symbol = ">".into();
-
- let output = run_delta(HUNK_ZERO_DIFF, &config);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│L│abcdefghijklm+ │RRRR│abcdefghijklm+",
- "│L│nopqrstuvwxzy+ │RRRR│nopqrstuvwxzy+",
- "│L│ 0123456789 0+ │RRRR│ 0123456789 0+",
- "│L│123456789 012+ │RRRR│123456789 012+",
- "│L│3456789 01234567>│RRRR│3456789 01234>",
- "│L│a = 1 │RRRR│a = 2 ",
- ];
- assert_eq!(lines, expected);
+ ]))
+ .set_cfg(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(HUNK_ZERO_DIFF)
+ .expect(
+ r#"
+ │L│abcdefghijklm+ │RRRR│abcdefghijklm+
+ │L│nopqrstuvwxzy+ │RRRR│nopqrstuvwxzy+
+ │L│ 0123456789 0+ │RRRR│ 0123456789 0+
+ │L│123456789 012+ │RRRR│123456789 012+
+ │L│3456789 01234567>│RRRR│3456789 01234>
+ │L│a = 1 │RRRR│a = 2 "#,
+ );
}
#[test]
fn test_wrap_with_large_hunk_zero_line_numbers() {
- let mut config = make_config_from_args(&default_wrap_cfg_plus(&[
+ DeltaTest::with(&default_wrap_cfg_plus(&[
"--side-by-side",
"--line-numbers-left-format",
"│LLL│",
@@ -943,53 +939,49 @@ index 223ca50..e69de29 100644
"60",
"--line-fill-method",
"ansi",
- ]));
- config.truncation_symbol = ">".into();
-
- let output = run_delta(HUNK_ZERO_LARGE_LINENUMBERS_DIFF, &config);
- let output = strip_ansi_codes(&output);
- 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+",
- "│LLL│klmno+ │WW +- WW│klmno+",
- "│LLL│pqrst+ │WW +- WW│pqrst+",
- "│LLL│uvwxzy 0123456789 012345>│WW +- WW│uvwxz>",
- "│LLL│a = 1 │WW +- 102000 WW│a = 2",
- ];
- assert_eq!(lines, expected);
+ ]))
+ .set_cfg(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(HUNK_ZERO_LARGE_LINENUMBERS_DIFF)
+ .expect(
+ r#"
+ │LLL│abcde+ │WW 10 +- 101999 WW│abcde+
+ │LLL│fghij+ │WW +- WW│fghij+
+ │LLL│klmno+ │WW +- WW│klmno+
+ │LLL│pqrst+ │WW +- WW│pqrst+
+ │LLL│uvwxzy 0123456789 012345>│WW +- WW│uvwxz>
+ │LLL│a = 1 │WW +- 102000 WW│a = 2"#,
+ );
}
#[test]
fn test_wrap_with_keep_markers() {
use crate::features::side_by_side::ansifill::ODD_PAD_CHAR;
- let mut config = make_config_from_args(&default_wrap_cfg_plus(&[
+ let t = DeltaTest::with(&default_wrap_cfg_plus(&[
"--side-by-side",
"--keep-plus-minus-markers",
"--width",
"45",
- ]));
- config.truncation_symbol = ">".into();
+ ]))
+ .set_cfg(|cfg| cfg.truncation_symbol = ">".into())
+ .with_input(HUNK_MP_DIFF);
+ let output = t.expect(
+ r#"
+ │ 4 │ abcdefghijklmn+ │ 15 │ abcdefghijklmn+
+ │ │ opqrstuvwxzy 0+ │ │ opqrstuvwxzy 0+
+ │ │ 123456789 0123+ │ │ 123456789 0123+
+ │ │ 456789 0123456+ │ │ 456789 0123456+
+ │ │ 789 0123456789> │ │ 789 0123456789>
+ │ 5 │-a = 0123456789+ │ 16 │+b = 0123456789+
+ │ │ 0123456789 01+ │ │ 0123456789 01+
+ │ │ 23456789 01234+ │ │ 23456789 01234+
+ │ │ 56789 01234567+ │ │ 56789 01234567+
+ │ │ 89 │ │ 89"#,
+ // this column here is^ where ODD_PAD_CHAR is inserted due to the odd 45 width
+ );
- let output = run_delta(HUNK_MP_DIFF, &config);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 4 │ abcdefghijklmn+ │ 15 │ abcdefghijklmn+",
- "│ │ opqrstuvwxzy 0+ │ │ opqrstuvwxzy 0+",
- "│ │ 123456789 0123+ │ │ 123456789 0123+",
- "│ │ 456789 0123456+ │ │ 456789 0123456+",
- "│ │ 789 0123456789> │ │ 789 0123456789>",
- "│ 5 │-a = 0123456789+ │ 16 │+b = 0123456789+",
- "│ │ 0123456789 01+ │ │ 0123456789 01+",
- "│ │ 23456789 01234+ │ │ 23456789 01234+",
- "│ │ 56789 01234567+ │ │ 56789 01234567+",
- "│ │ 89 │ │ 89",
- // this is place where ^ ODD_PAD_CHAR is inserted due to the odd 45 width
- ];
- assert_eq!(lines, expected);
+ assert!(!output.is_empty());
- for line in lines {
+ for line in output.lines().skip(crate::config::HEADER_LEN) {
assert_eq!(line.chars().nth(22), Some(ODD_PAD_CHAR));
}
}
@@ -999,40 +991,36 @@ index 223ca50..e69de29 100644
let config =
make_config_from_args(&default_wrap_cfg_plus(&["--side-by-side", "--width", "55"]));
{
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_SHORT, HUNK_ALIGN_DIFF_LONG
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2< │ 1 │.........1.........2+
+ │ │ >.... │ │.........3.........4+
+ │ │ │ │.........5.........6"#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2< │ 1 │.........1.........2+",
- "│ │ >.... │ │.........3.........4+",
- "│ │ │ │.........5.........6",
- // place where ODD_PAD_CHAR ^ is inserted due to the odd 55 width
- ];
- assert_eq!(lines, expected);
+ // the place where ODD_PAD_CHAR^ is inserted due to the odd 55 width
}
{
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_LONG, HUNK_ALIGN_DIFF_SHORT
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2+ │ 1 │.........1.........2<
+ │ │.........3.........4+ │ │ >....
+ │ │.........5.........6 │ │"#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2+ │ 1 │.........1.........2<",
- "│ │.........3.........4+ │ │ >....",
- "│ │.........5.........6 │ │",
- ];
- assert_eq!(lines, expected);
}
}
@@ -1047,39 +1035,35 @@ index 223ca50..e69de29 100644
]));
{
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_SHORT, HUNK_ALIGN_DIFF_LONG
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2....│ 1 │.........1.........2...+
+ │ │ │ │......3.........4......+
+ │ │ │ │...5.........6 "#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2....│ 1 │.........1.........2...+",
- "│ │ │ │......3.........4......+",
- "│ │ │ │...5.........6 ",
- ];
- assert_eq!(lines, expected);
}
{
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_LONG, HUNK_ALIGN_DIFF_SHORT
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2...+│ 1 │.........1.........2....
+ │ │......3.........4......+│ │
+ │ │...5.........6 │ │"#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2...+│ 1 │.........1.........2....",
- "│ │......3.........4......+│ │",
- "│ │...5.........6 │ │",
- ];
- assert_eq!(lines, expected);
}
}
@@ -1098,39 +1082,35 @@ index 223ca50..e69de29 100644
config.truncation_symbol = ">".into();
{
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_SHORT, HUNK_ALIGN_DIFF_LONG
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2.... │ 1 │.........1.........2.........+
+ │ │ │ │3.........4.........5........+
+ │ │ │ │.6 "#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2.... │ 1 │.........1.........2.........+",
- "│ │ │ │3.........4.........5........+",
- "│ │ │ │.6 ",
- ];
- assert_eq!(lines, expected);
}
{
config.wrap_config.max_lines = 2;
- let output = run_delta(
+ DeltaTest::with_config_and_input(
+ &config,
&format!(
"{}-{}+{}",
HUNK_ALIGN_DIFF_HEADER, HUNK_ALIGN_DIFF_SHORT, HUNK_ALIGN_DIFF_LONG
),
- &config,
+ )
+ .expect(
+ r#"
+ │ 1 │.........1.........2.... │ 1 │.........1.........2.........+
+ │ │ │ │3.........4.........5........>"#,
);
- let output = strip_ansi_codes(&output);
- let lines: Vec<_> = output.lines().skip(crate::config::HEADER_LEN).collect();
- let expected = vec![
- "│ 1 │.........1.........2.... │ 1 │.........1.........2.........+",
- "│ │ │ │3.........4.........5........>",
- ];
- assert_eq!(lines, expected);
}
}
}