just playing with tangled
1// Copyright 2022 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15use common::TestEnvironment; 16 17pub mod common; 18 19#[test] 20fn test_interdiff_basic() { 21 let test_env = TestEnvironment::default(); 22 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 23 let repo_path = test_env.env_root().join("repo"); 24 25 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 26 test_env.jj_cmd_success(&repo_path, &["new"]); 27 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 28 test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]); 29 30 test_env.jj_cmd_success(&repo_path, &["checkout", "root"]); 31 std::fs::write(repo_path.join("file3"), "foo\n").unwrap(); 32 test_env.jj_cmd_success(&repo_path, &["new"]); 33 std::fs::write(repo_path.join("file2"), "foo\nbar\n").unwrap(); 34 test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]); 35 36 // implicit --to 37 let stdout = test_env.jj_cmd_success(&repo_path, &["interdiff", "--from", "left"]); 38 insta::assert_snapshot!(stdout, @r###" 39 Modified regular file file2: 40 1 1: foo 41 2: bar 42 "###); 43 44 // explicit --to 45 test_env.jj_cmd_success(&repo_path, &["checkout", "@-"]); 46 let stdout = test_env.jj_cmd_success( 47 &repo_path, 48 &["interdiff", "--from", "left", "--to", "right"], 49 ); 50 insta::assert_snapshot!(stdout, @r###" 51 Modified regular file file2: 52 1 1: foo 53 2: bar 54 "###); 55 test_env.jj_cmd_success(&repo_path, &["undo"]); 56 57 // formats specifiers 58 let stdout = test_env.jj_cmd_success( 59 &repo_path, 60 &["interdiff", "--from", "left", "--to", "right", "-s"], 61 ); 62 insta::assert_snapshot!(stdout, @r###" 63 M file2 64 "###); 65 66 let stdout = test_env.jj_cmd_success( 67 &repo_path, 68 &["interdiff", "--from", "left", "--to", "right", "--git"], 69 ); 70 insta::assert_snapshot!(stdout, @r###" 71 diff --git a/file2 b/file2 72 index 257cc5642c...3bd1f0e297 100644 73 --- a/file2 74 +++ b/file2 75 @@ -1,1 +1,2 @@ 76 foo 77 +bar 78 "###); 79} 80 81#[test] 82fn test_interdiff_paths() { 83 let test_env = TestEnvironment::default(); 84 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 85 let repo_path = test_env.env_root().join("repo"); 86 87 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 88 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 89 test_env.jj_cmd_success(&repo_path, &["new"]); 90 std::fs::write(repo_path.join("file1"), "bar\n").unwrap(); 91 std::fs::write(repo_path.join("file2"), "bar\n").unwrap(); 92 test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]); 93 94 test_env.jj_cmd_success(&repo_path, &["checkout", "root"]); 95 std::fs::write(repo_path.join("file1"), "foo\n").unwrap(); 96 std::fs::write(repo_path.join("file2"), "foo\n").unwrap(); 97 test_env.jj_cmd_success(&repo_path, &["new"]); 98 std::fs::write(repo_path.join("file1"), "baz\n").unwrap(); 99 std::fs::write(repo_path.join("file2"), "baz\n").unwrap(); 100 test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]); 101 102 let stdout = test_env.jj_cmd_success( 103 &repo_path, 104 &["interdiff", "--from", "left", "--to", "right", "file1"], 105 ); 106 insta::assert_snapshot!(stdout, @r###" 107 Modified regular file file1: 108 1 1: barbaz 109 "###); 110 111 let stdout = test_env.jj_cmd_success( 112 &repo_path, 113 &[ 114 "interdiff", 115 "--from", 116 "left", 117 "--to", 118 "right", 119 "file1", 120 "file2", 121 ], 122 ); 123 insta::assert_snapshot!(stdout, @r###" 124 Modified regular file file1: 125 1 1: barbaz 126 Modified regular file file2: 127 1 1: barbaz 128 "###); 129} 130 131#[test] 132fn test_interdiff_conflicting() { 133 let test_env = TestEnvironment::default(); 134 test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); 135 let repo_path = test_env.env_root().join("repo"); 136 137 std::fs::write(repo_path.join("file"), "foo\n").unwrap(); 138 test_env.jj_cmd_success(&repo_path, &["new"]); 139 std::fs::write(repo_path.join("file"), "bar\n").unwrap(); 140 test_env.jj_cmd_success(&repo_path, &["branch", "create", "left"]); 141 142 test_env.jj_cmd_success(&repo_path, &["checkout", "root"]); 143 std::fs::write(repo_path.join("file"), "abc\n").unwrap(); 144 test_env.jj_cmd_success(&repo_path, &["new"]); 145 std::fs::write(repo_path.join("file"), "def\n").unwrap(); 146 test_env.jj_cmd_success(&repo_path, &["branch", "create", "right"]); 147 148 let stdout = test_env.jj_cmd_success( 149 &repo_path, 150 &["interdiff", "--from", "left", "--to", "right", "--git"], 151 ); 152 insta::assert_snapshot!(stdout, @r###" 153 diff --git a/file b/file 154 index f845ab93f0...24c5735c3e 100644 155 --- a/file 156 +++ b/file 157 @@ -1,7 +1,1 @@ 158 -<<<<<<< 159 -%%%%%%% 160 --foo 161 -+abc 162 -+++++++ 163 -bar 164 ->>>>>>> 165 +def 166 "###); 167}