encoding/base32: Add encode->decode roundtrip test

Add test_base32_roundtrip() to verify the encode->decode roundtrip
preserves data integrity. This test helps ensure our base32 implementation
correctly handles the full encode->decode cycle without data loss or
corruption.
This commit is contained in:
Zoltán Kéri
2024-12-30 03:03:50 +01:00
parent c9c59edc64
commit 0d4c0064d9
+23
View File
@@ -125,3 +125,26 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
testing.expect_value(t, err, Error.Invalid_Length)
}
}
@(test)
test_base32_roundtrip :: proc(t: ^testing.T) {
cases := [?]string{
"",
"f",
"fo",
"foo",
"foob",
"fooba",
"foobar",
}
for input in cases {
encoded := encode(transmute([]byte)input)
decoded, err := decode(encoded)
if decoded != nil {
defer delete(decoded)
}
testing.expect_value(t, err, Error.None)
testing.expect(t, bytes.equal(decoded, transmute([]byte)input))
}
}