From 0d4c0064d961d8a50901afd8c359962b687d1cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20K=C3=A9ri?= Date: Mon, 30 Dec 2024 03:03:50 +0100 Subject: [PATCH] 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. --- core/encoding/base32/base32_test.odin | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/encoding/base32/base32_test.odin b/core/encoding/base32/base32_test.odin index e492f9a85..6589abc42 100644 --- a/core/encoding/base32/base32_test.odin +++ b/core/encoding/base32/base32_test.odin @@ -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)) + } +}