From 6a7fc936c4a969aa05b3941feedafe59f4bd2ffd Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 21 Feb 2026 15:54:26 +0800 Subject: *: Add more tests --- object/commit_parse_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'object') diff --git a/object/commit_parse_test.go b/object/commit_parse_test.go index f01052ac..a29ab1fa 100644 --- a/object/commit_parse_test.go +++ b/object/commit_parse_test.go @@ -2,6 +2,7 @@ package object_test import ( "bytes" + "fmt" "testing" "codeberg.org/lindenii/furgit/internal/testgit" @@ -37,3 +38,43 @@ func TestCommitParseFromGit(t *testing.T) { } }) } + +func TestCommitParseMultipleParents(t *testing.T) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) + + _, treeID := testRepo.MakeSingleFileTree(t, "file.txt", []byte("merge-content\n")) + parent1 := testRepo.CommitTree(t, treeID, "parent-one") + parent2 := testRepo.CommitTree(t, treeID, "parent-two", parent1) + + rawCommit := fmt.Sprintf( + "tree %s\nparent %s\nparent %s\nauthor Test Author 1234567890 +0000\ncommitter Test Committer 1234567890 +0000\n\nMerge commit\n", + treeID, + parent1, + parent2, + ) + mergeID := testRepo.HashObject(t, "commit", []byte(rawCommit)) + rawBody := testRepo.CatFile(t, "commit", mergeID) + + commit, err := object.ParseCommit(rawBody, algo) + if err != nil { + t.Fatalf("ParseCommit(merge): %v", err) + } + if commit.Tree != treeID { + t.Fatalf("merge tree = %s, want %s", commit.Tree, treeID) + } + if len(commit.Parents) != 2 { + t.Fatalf("merge parent count = %d, want 2", len(commit.Parents)) + } + if commit.Parents[0] != parent1 { + t.Fatalf("merge parent[0] = %s, want %s", commit.Parents[0], parent1) + } + if commit.Parents[1] != parent2 { + t.Fatalf("merge parent[1] = %s, want %s", commit.Parents[1], parent2) + } + if !bytes.Equal(commit.Message, []byte("Merge commit\n")) { + t.Fatalf("merge message = %q, want %q", commit.Message, "Merge commit\n") + } + }) +} -- cgit v1.3.1-10-gc9f91