just playing with tangled
at gvimdiff 4.8 kB view raw
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 crate::common::TestEnvironment; 16 17#[test] 18fn test_interdiff_basic() { 19 let test_env = TestEnvironment::default(); 20 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 21 let work_dir = test_env.work_dir("repo"); 22 23 work_dir.write_file("file1", "foo\n"); 24 work_dir.run_jj(["new"]).success(); 25 work_dir.write_file("file2", "foo\n"); 26 work_dir 27 .run_jj(["bookmark", "create", "-r@", "left"]) 28 .success(); 29 30 work_dir.run_jj(["new", "root()"]).success(); 31 work_dir.write_file("file3", "foo\n"); 32 work_dir.run_jj(["new"]).success(); 33 work_dir.write_file("file2", "foo\nbar\n"); 34 work_dir 35 .run_jj(["bookmark", "create", "-r@", "right"]) 36 .success(); 37 38 // implicit --to 39 let output = work_dir.run_jj(["interdiff", "--from", "left"]); 40 insta::assert_snapshot!(output, @r" 41 Modified regular file file2: 42 1 1: foo 43 2: bar 44 [EOF] 45 "); 46 47 // explicit --to 48 work_dir.run_jj(["new", "@-"]).success(); 49 let output = work_dir.run_jj(["interdiff", "--from", "left", "--to", "right"]); 50 insta::assert_snapshot!(output, @r" 51 Modified regular file file2: 52 1 1: foo 53 2: bar 54 [EOF] 55 "); 56 work_dir.run_jj(["undo"]).success(); 57 58 // formats specifiers 59 let output = work_dir.run_jj(["interdiff", "--from", "left", "--to", "right", "-s"]); 60 insta::assert_snapshot!(output, @r" 61 M file2 62 [EOF] 63 "); 64 65 let output = work_dir.run_jj(["interdiff", "--from", "left", "--to", "right", "--git"]); 66 insta::assert_snapshot!(output, @r" 67 diff --git a/file2 b/file2 68 index 257cc5642c..3bd1f0e297 100644 69 --- a/file2 70 +++ b/file2 71 @@ -1,1 +1,2 @@ 72 foo 73 +bar 74 [EOF] 75 "); 76} 77 78#[test] 79fn test_interdiff_paths() { 80 let test_env = TestEnvironment::default(); 81 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 82 let work_dir = test_env.work_dir("repo"); 83 84 work_dir.write_file("file1", "foo\n"); 85 work_dir.write_file("file2", "foo\n"); 86 work_dir.run_jj(["new"]).success(); 87 work_dir.write_file("file1", "bar\n"); 88 work_dir.write_file("file2", "bar\n"); 89 work_dir 90 .run_jj(["bookmark", "create", "-r@", "left"]) 91 .success(); 92 93 work_dir.run_jj(["new", "root()"]).success(); 94 work_dir.write_file("file1", "foo\n"); 95 work_dir.write_file("file2", "foo\n"); 96 work_dir.run_jj(["new"]).success(); 97 work_dir.write_file("file1", "baz\n"); 98 work_dir.write_file("file2", "baz\n"); 99 work_dir 100 .run_jj(["bookmark", "create", "-r@", "right"]) 101 .success(); 102 103 let output = work_dir.run_jj(["interdiff", "--from", "left", "--to", "right", "file1"]); 104 insta::assert_snapshot!(output, @r" 105 Modified regular file file1: 106 1 1: barbaz 107 [EOF] 108 "); 109 110 let output = work_dir.run_jj([ 111 "interdiff", 112 "--from", 113 "left", 114 "--to", 115 "right", 116 "file1", 117 "file2", 118 ]); 119 insta::assert_snapshot!(output, @r" 120 Modified regular file file1: 121 1 1: barbaz 122 Modified regular file file2: 123 1 1: barbaz 124 [EOF] 125 "); 126} 127 128#[test] 129fn test_interdiff_conflicting() { 130 let test_env = TestEnvironment::default(); 131 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 132 let work_dir = test_env.work_dir("repo"); 133 134 work_dir.write_file("file", "foo\n"); 135 work_dir.run_jj(["new"]).success(); 136 work_dir.write_file("file", "bar\n"); 137 work_dir 138 .run_jj(["bookmark", "create", "-r@", "left"]) 139 .success(); 140 141 work_dir.run_jj(["new", "root()"]).success(); 142 work_dir.write_file("file", "abc\n"); 143 work_dir.run_jj(["new"]).success(); 144 work_dir.write_file("file", "def\n"); 145 work_dir 146 .run_jj(["bookmark", "create", "-r@", "right"]) 147 .success(); 148 149 let output = work_dir.run_jj(["interdiff", "--from", "left", "--to", "right", "--git"]); 150 insta::assert_snapshot!(output, @r" 151 diff --git a/file b/file 152 index 0000000000..24c5735c3e 100644 153 --- a/file 154 +++ b/file 155 @@ -1,7 +1,1 @@ 156 -<<<<<<< Conflict 1 of 1 157 -%%%%%%% Changes from base to side #1 158 --foo 159 -+abc 160 -+++++++ Contents of side #2 161 -bar 162 ->>>>>>> Conflict 1 of 1 ends 163 +def 164 [EOF] 165 "); 166}