From d26449f260cb4a02bb6949c315580ea31bc29de8 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 20 Feb 2026 21:33:39 +0800 Subject: object: Add tests --- object/commit_parse_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 object/commit_parse_test.go (limited to 'object/commit_parse_test.go') diff --git a/object/commit_parse_test.go b/object/commit_parse_test.go new file mode 100644 index 00000000..8d1f192d --- /dev/null +++ b/object/commit_parse_test.go @@ -0,0 +1,38 @@ +package object_test + +import ( + "bytes" + "testing" + + "codeberg.org/lindenii/furgit/internal/testgit" + "codeberg.org/lindenii/furgit/object" + "codeberg.org/lindenii/furgit/oid" +) + +func TestCommitParseFromGit(t *testing.T) { + testgit.ForEachAlgorithm(t, func(t *testing.T, algo oid.Algorithm) { + repo := testgit.NewBareRepo(t, algo) + _, treeID, commitID := repo.MakeCommit(t, "subject\n\nbody") + + rawBody := repo.CatFile(t, "commit", commitID) + commit, err := object.ParseCommit(rawBody, algo) + if err != nil { + t.Fatalf("ParseCommit: %v", err) + } + if commit.Tree != treeID { + t.Fatalf("tree id mismatch: got %s want %s", commit.Tree, treeID) + } + if len(commit.Parents) != 0 { + t.Fatalf("parent count = %d, want 0", len(commit.Parents)) + } + if !bytes.Equal(commit.Author.Name, []byte("Test Author")) { + t.Fatalf("author name = %q, want %q", commit.Author.Name, "Test Author") + } + if !bytes.Equal(commit.Committer.Name, []byte("Test Committer")) { + t.Fatalf("committer name = %q, want %q", commit.Committer.Name, "Test Committer") + } + if !bytes.Contains(commit.Message, []byte("subject")) { + t.Fatalf("commit message missing subject: %q", commit.Message) + } + }) +} -- cgit v1.3.1-10-gc9f91