diff options
| author | 2026-03-25 14:49:17 +0000 | |
|---|---|---|
| committer | 2026-03-25 15:02:22 +0000 | |
| commit | 7847657e0820af98120031f719b8ede635ad8c07 (patch) | |
| tree | 8c4439c78f72f1382edc809b49be33115847b6e7 /object/commit_parse_test.go | |
| parent | object: Remove type.go (diff) | |
| signature | No signature | |
object: Split each object type into its own package v0.1.108
Diffstat (limited to 'object/commit_parse_test.go')
| -rw-r--r-- | object/commit_parse_test.go | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/object/commit_parse_test.go b/object/commit_parse_test.go deleted file mode 100644 index fae2b4c1..00000000 --- a/object/commit_parse_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package object_test - -import ( - "bytes" - "fmt" - "testing" - - "codeberg.org/lindenii/furgit/internal/testgit" - "codeberg.org/lindenii/furgit/object" - objectid "codeberg.org/lindenii/furgit/object/id" -) - -func TestCommitParseFromGit(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, commitID := testRepo.MakeCommit(t, "subject\n\nbody") - - rawBody := testRepo.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) - } - }) -} - -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 <test@example.org> 1234567890 +0000\ncommitter Test Committer <committer@example.org> 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") - } - }) -} |
