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
commit5cfbd8863dfb7c6af92497d9a5eb6eb63a6bd589 (patch)
tree42a871a72388bb6d40c479fbaa6eedde1cddc42e /hash_test.go
parenthash: Generic hash-algorithm API (diff)
signature
Revert "hash: Generic hash-algorithm API"
This reverts commit 94bfb1fa147f80e6ec39009d41fc2f853925e0a5. Generics actually kinda suck for these purposes... once you look at it from the user's perspective.
Diffstat (limited to 'hash_test.go')
-rw-r--r--hash_test.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/hash_test.go b/hash_test.go
index a6215a36..4b359c4a 100644
--- a/hash_test.go
+++ b/hash_test.go
@@ -10,34 +10,33 @@ func TestParseHashValidAndInvalid(t *testing.T) {
repeats := (testHashSize*2 + len(pattern) - 1) / len(pattern)
hexStr := strings.Repeat(pattern, repeats)[:testHashSize*2]
- id, err := ParseHash[testHashType](hexStr)
+ id, err := ParseHashWithSize(hexStr, testHashSize)
if err != nil {
t.Fatalf("ParseHash returned error: %v", err)
}
- if got := id.String(); got != hexStr {
+ if got := id.StringWithSize(testHashSize); got != hexStr {
t.Fatalf("unexpected String result: %q", got)
}
- if _, err := ParseHash[testHashType]("abcd"); err == nil {
+ if _, err := ParseHashWithSize("abcd", testHashSize); err == nil {
t.Fatal("expected error for short hash")
}
badHex := strings.Repeat("z", testHashSize*2)
- if _, err := ParseHash[testHashType](badHex); err == nil {
+ if _, err := ParseHashWithSize(badHex, testHashSize); err == nil {
t.Fatal("expected error for non-hex input")
}
}
-func TestHashTypeCopiesUnderlyingData(t *testing.T) {
- var id TestHash
- idSlice := id.Slice()
- for i := range idSlice {
- idSlice[i] = byte(i)
+func TestHashBytesCopiesUnderlyingData(t *testing.T) {
+ var id Hash
+ for i := range id {
+ id[i] = byte(i)
}
- orig := id.Bytes()
+ orig := id.BytesWithSize(testHashSize)
orig[0] ^= 0xff
- if idSlice[0] == orig[0] {
+ if id[0] == orig[0] {
t.Fatal("Bytes should return a copy")
}
}