From f934fb1acfc5ee59ffa5a36df53fdd726255a6c3 Mon Sep 17 00:00:00 2001 From: Jan Riemer <2428387-janriemer@users.noreply.gitlab.com> Date: Sun, 5 Nov 2023 17:20:28 +0100 Subject: [PATCH] `diff`: add tests for `--delimiter-output` --- tests/test_diff.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_diff.rs b/tests/test_diff.rs index db4f244fa..a6c3dd1ba 100644 --- a/tests/test_diff.rs +++ b/tests/test_diff.rs @@ -425,6 +425,48 @@ fn diff_left_has_one_column_right_has_none_headers_in_result() { assert_eq!(got, expected); } +#[test] +fn diff_with_default_delimiter_in_result() { + let wrk = Workdir::new("diff_with_default_delimiter_in_result"); + + let left = vec![svec!["h1", "h2", "h3"], svec!["1", "foo", "bar"]]; + wrk.create("left.csv", left); + + let right = vec![svec!["h1", "h2", "h3"], svec!["1", "foo_changed", "bar"]]; + wrk.create("right.csv", right); + + let mut cmd = wrk.command("diff"); + cmd.args(["left.csv", "right.csv"]); + + let got: String = wrk.stdout(&mut cmd); + let expected = "\ +diffresult,h1,h2,h3 +-,1,foo,bar ++,1,foo_changed,bar"; + assert_eq!(got.as_str(), expected); +} + +#[test] +fn diff_with_different_delimiter_in_result() { + let wrk = Workdir::new("diff_with_different_delimiter_in_result"); + + let left = vec![svec!["h1", "h2", "h3"], svec!["1", "foo", "bar"]]; + wrk.create("left.csv", left); + + let right = vec![svec!["h1", "h2", "h3"], svec!["1", "foo_changed", "bar"]]; + wrk.create("right.csv", right); + + let mut cmd = wrk.command("diff"); + cmd.args(["left.csv", "right.csv", "--delimiter-output", ";"]); + + let got: String = wrk.stdout(&mut cmd); + let expected = "\ +diffresult;h1;h2;h3 +-;1;foo;bar ++;1;foo_changed;bar"; + assert_eq!(got.as_str(), expected); +} + fn create_file_with_delim(wrk: &Workdir, file_path_new: &str, file_path: &str, delimiter: u8) { let mut select_cmd = wrk.command("select"); select_cmd.args(["1-", file_path]);