aboutsummaryrefslogtreecommitdiff
path: root/hash_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commitbd91bf5f3bcffe5d1023ab9a37e4a9425830aba9 (patch)
treee6e9fb33bfa5c455a824f0af065c54529d357c0c /hash_test.go
parentRevert "hash: Generic hash-algorithm API" (diff)
signature
hash: Make fewer helper functions need explicit hash length fields
Diffstat (limited to 'hash_test.go')
-rw-r--r--hash_test.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/hash_test.go b/hash_test.go
index 4b359c4a..89e66fd1 100644
--- a/hash_test.go
+++ b/hash_test.go
@@ -9,34 +9,36 @@ func TestParseHashValidAndInvalid(t *testing.T) {
pattern := "0123456789abcdef"
repeats := (testHashSize*2 + len(pattern) - 1) / len(pattern)
hexStr := strings.Repeat(pattern, repeats)[:testHashSize*2]
-
- id, err := ParseHashWithSize(hexStr, testHashSize)
+
+ repo := &Repository{HashSize: testHashSize}
+ id, err := repo.ParseHash(hexStr)
if err != nil {
t.Fatalf("ParseHash returned error: %v", err)
}
- if got := id.StringWithSize(testHashSize); got != hexStr {
+ if got := id.String(); got != hexStr {
t.Fatalf("unexpected String result: %q", got)
}
- if _, err := ParseHashWithSize("abcd", testHashSize); err == nil {
+ if _, err := repo.ParseHash("abcd"); err == nil {
t.Fatal("expected error for short hash")
}
badHex := strings.Repeat("z", testHashSize*2)
- if _, err := ParseHashWithSize(badHex, testHashSize); err == nil {
+ if _, err := repo.ParseHash(badHex); 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)
+ for i := range id.data {
+ id.data[i] = byte(i)
}
- orig := id.BytesWithSize(testHashSize)
+ id.size = testHashSize
+ orig := id.Bytes()
orig[0] ^= 0xff
- if id[0] == orig[0] {
+ if id.data[0] == orig[0] {
t.Fatal("Bytes should return a copy")
}
}