3 test_description
='anchored diff algorithm'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'--anchored' '
9 printf "a\nb\nc\n" >pre &&
10 printf "c\na\nb\n" >post &&
12 # normally, c is moved to produce the smallest diff
13 test_expect_code 1 git diff --no-index pre post >diff &&
16 # with anchor, a is moved
17 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
21 test_expect_success
'--anchored multiple' '
22 printf "a\nb\nc\nd\ne\nf\n" >pre &&
23 printf "c\na\nb\nf\nd\ne\n" >post &&
25 # with 1 anchor, c is not moved, but f is moved
26 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
27 grep "^+a" diff && # a is moved instead of c
30 # with 2 anchors, c and f are not moved
31 test_expect_code 1 git diff --no-index --anchored=c --anchored=f pre post >diff &&
33 grep "^+d" diff # d is moved instead of f
36 test_expect_success
'--anchored with nonexistent line has no effect' '
37 printf "a\nb\nc\n" >pre &&
38 printf "c\na\nb\n" >post &&
40 test_expect_code 1 git diff --no-index --anchored=x pre post >diff &&
44 test_expect_success
'--anchored with non-unique line has no effect' '
45 printf "a\nb\nc\nd\ne\nc\n" >pre &&
46 printf "c\na\nb\nc\nd\ne\n" >post &&
48 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
52 test_expect_success
'diff still produced with impossible multiple --anchored' '
53 printf "a\nb\nc\n" >pre &&
54 printf "c\na\nb\n" >post &&
56 test_expect_code 1 git diff --no-index --anchored=a --anchored=c pre post >diff &&
57 mv post expected_post &&
59 # Ensure that the diff is correct by applying it and then
60 # comparing the result with the original
62 diff expected_post post
65 test_expect_success
'later algorithm arguments override earlier ones' '
66 printf "a\nb\nc\n" >pre &&
67 printf "c\na\nb\n" >post &&
69 test_expect_code 1 git diff --no-index --patience --anchored=c pre post >diff &&
72 test_expect_code 1 git diff --no-index --anchored=c --patience pre post >diff &&
75 test_expect_code 1 git diff --no-index --histogram --anchored=c pre post >diff &&
78 test_expect_code 1 git diff --no-index --anchored=c --histogram pre post >diff &&
82 test_expect_success
'--anchored works with other commands like "git show"' '
83 printf "a\nb\nc\n" >file &&
86 printf "c\na\nb\n" >file &&
90 # with anchor, a is moved
91 git show --patience --anchored=c >diff &&