From be35ab164cef578031809dbcecb0f311c2a19b28 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 16 Aug 2024 09:38:44 +0900 Subject: [PATCH] tests: restore snapshots of line/word-oriented diff hunks test_diff_basic() is now testing file-level changes such as renames. --- cli/tests/test_diff_command.rs | 91 ++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/cli/tests/test_diff_command.rs b/cli/tests/test_diff_command.rs index 59b233fc2f..5e78667166 100644 --- a/cli/tests/test_diff_command.rs +++ b/cli/tests/test_diff_command.rs @@ -649,6 +649,97 @@ fn test_diff_relative_paths() { "###); } +#[test] +fn test_diff_hunks() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); + let repo_path = test_env.env_root().join("repo"); + + // Test added, removed, inserted, and modified lines. The modified line + // contains unchanged words. + std::fs::write(repo_path.join("file1"), "").unwrap(); + std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); + std::fs::write(repo_path.join("file3"), "foo\nbaz qux blah blah\n").unwrap(); + test_env.jj_cmd_ok(&repo_path, &["new"]); + std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); + std::fs::write(repo_path.join("file2"), "").unwrap(); + std::fs::write(repo_path.join("file3"), "foo\nbar\nbaz quux blah blah\n").unwrap(); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff"]); + insta::assert_snapshot!(stdout, @r###" + Modified regular file file1: + 1: foo + Modified regular file file2: + 1 : foo + Modified regular file file3: + 1 1: foo + 2: bar + 2 3: baz quxquux blah blah + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--color=debug"]); + insta::assert_snapshot!(stdout, @r###" + <> + <><><><> + <> + <><><> + <> + <><><><> + <><><><> + <><><><><><><> + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git"]); + insta::assert_snapshot!(stdout, @r###" + diff --git a/file1 b/file1 + index e69de29bb2..257cc5642c 100644 + --- a/file1 + +++ b/file1 + @@ -1,0 +1,1 @@ + +foo + diff --git a/file2 b/file2 + index 257cc5642c..e69de29bb2 100644 + --- a/file2 + +++ b/file2 + @@ -1,1 +1,0 @@ + -foo + diff --git a/file3 b/file3 + index 221a95a095..a543ef3892 100644 + --- a/file3 + +++ b/file3 + @@ -1,2 +1,3 @@ + foo + -baz qux blah blah + +bar + +baz quux blah blah + "###); + + let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "--git", "--color=debug"]); + insta::assert_snapshot!(stdout, @r###" + <> + <> + <> + <> + <> + <><> + <> + <> + <> + <> + <> + <><> + <> + <> + <> + <> + <> + <> + <><><> + <><> + <><><> + "###); +} + #[test] fn test_diff_missing_newline() { let test_env = TestEnvironment::default();