Przeglądaj źródła

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.
Zoltán Kéri 9 miesięcy temu
rodzic
commit
0d4c0064d9
1 zmienionych plików z 23 dodań i 0 usunięć
  1. 23 0
      core/encoding/base32/base32_test.odin

+ 23 - 0
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))
+	}
+}