diff options
| author | 2025-11-11 00:00:00 +0000 | |
|---|---|---|
| committer | 2025-11-13 00:00:00 +0000 | |
| commit | 15855e3249754ab7dc07183c9383f8a8e8c26af2 (patch) | |
| tree | 83b32bdd63f7e672152f07d89268e9b268d1f3f5 /hash_test.go | |
| signature | ||
Initial commit
Diffstat (limited to 'hash_test.go')
| -rw-r--r-- | hash_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/hash_test.go b/hash_test.go new file mode 100644 index 00000000..95660d88 --- /dev/null +++ b/hash_test.go @@ -0,0 +1,33 @@ +package furgit + +import "testing" + +func TestParseHashValidAndInvalid(t *testing.T) { + const hex40 = "0123456789abcdef0123456789abcdef01234567" + id, err := ParseHash(hex40) + if err != nil { + t.Fatalf("ParseHash returned error: %v", err) + } + if got := id.String(); got != hex40 { + t.Fatalf("unexpected String result: %q", got) + } + + if _, err := ParseHash("abcd"); err == nil { + t.Fatal("expected error for short hash") + } + if _, err := ParseHash("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); err == nil { + t.Fatal("expected error for non-hex input") + } +} + +func TestHashBytesCopiesUnderlyingData(t *testing.T) { + var id Hash + for i := range id { + id[i] = byte(i) + } + orig := id.Bytes() + orig[0] ^= 0xff + if id[0] == orig[0] { + t.Fatal("Bytes should return a copy") + } +} |
