MCPcopy Create free account
hub / github.com/libgit2/git2go / TestFindSimilar

Function TestFindSimilar

diff_test.go:13–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestFindSimilar(t *testing.T) {
14 t.Parallel()
15 repo := createTestRepo(t)
16 defer cleanupTestRepo(t, repo)
17
18 originalTree, newTree := createTestTrees(t, repo)
19
20 diffOpt, _ := DefaultDiffOptions()
21
22 diff, err := repo.DiffTreeToTree(originalTree, newTree, &diffOpt)
23 checkFatal(t, err)
24 if diff == nil {
25 t.Fatal("no diff returned")
26 }
27
28 findOpts, err := DefaultDiffFindOptions()
29 checkFatal(t, err)
30 findOpts.Flags = DiffFindBreakRewrites
31
32 err = diff.FindSimilar(&findOpts)
33 checkFatal(t, err)
34
35 numDiffs := 0
36 numAdded := 0
37 numDeleted := 0
38
39 err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
40 numDiffs++
41
42 switch file.Status {
43 case DeltaAdded:
44 numAdded++
45 case DeltaDeleted:
46 numDeleted++
47 }
48
49 return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
50 return func(line DiffLine) error {
51 return nil
52 }, nil
53 }, nil
54 }, DiffDetailLines)
55
56 if numDiffs != 2 {
57 t.Fatal("Incorrect number of files in diff")
58 }
59 if numAdded != 1 {
60 t.Fatal("Incorrect number of new files in diff")
61 }
62 if numDeleted != 1 {
63 t.Fatal("Incorrect number of deleted files in diff")
64 }
65
66}
67
68func TestDiffTreeToTree(t *testing.T) {
69 t.Parallel()

Callers

nothing calls this directly

Calls 9

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
createTestTreesFunction · 0.85
DefaultDiffOptionsFunction · 0.85
checkFatalFunction · 0.85
DefaultDiffFindOptionsFunction · 0.85
DiffTreeToTreeMethod · 0.80
FindSimilarMethod · 0.80
ForEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…