Package lines for base32, move its tests to tests"

This commit is contained in:
Jeroen van Rijn
2025-10-09 15:27:53 +02:00
parent 153b0de420
commit aec7d6480b
5 changed files with 28 additions and 18 deletions

2
core/debug/pe/doc.odin Normal file
View File

@@ -0,0 +1,2 @@
// package pe implements a reader for the PE executable format for debug purposes
package debug_pe

View File

@@ -1,6 +1,8 @@
package encoding_base32
// Base32 encoding/decoding implementation as specified in RFC 4648.
// [[ More; https://www.rfc-editor.org/rfc/rfc4648.html ]]
package encoding_base32
// @note(zh): Encoding utility for Base32
// A secondary param can be used to supply a custom alphabet to

View File

@@ -0,0 +1,2 @@
// package base32 implements Base32 encoding/decoding, as specified in RFC 4648.
package encoding_base32

View File

@@ -1,8 +1,11 @@
#+test
package encoding_base32
package test_encoding_base32
import "core:testing"
import "core:bytes"
import "core:encoding/base32"
Error :: base32.Error
@(test)
test_base32_decode_valid :: proc(t: ^testing.T) {
@@ -20,7 +23,7 @@ test_base32_decode_valid :: proc(t: ^testing.T) {
}
for c in cases {
output, err := decode(c.input)
output, err := base32.decode(c.input)
if output != nil {
defer delete(output)
}
@@ -50,7 +53,7 @@ test_base32_encode :: proc(t: ^testing.T) {
}
for c in cases {
output := encode(transmute([]byte)c.input)
output := base32.encode(transmute([]byte)c.input)
defer delete(output)
testing.expect(t, output == c.expected)
}
@@ -62,7 +65,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Characters outside alphabet
input := "MZ1W6YTB" // '1' not in alphabet (A-Z, 2-7)
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -71,7 +74,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Lowercase not allowed
input := "mzxq===="
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -82,7 +85,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Padding must only be at end
input := "MZ=Q===="
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -91,7 +94,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Missing padding
input := "MZXQ" // Should be MZXQ====
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -100,7 +103,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Incorrect padding length
input := "MZXQ=" // Needs 4 padding chars
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -109,7 +112,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Too much padding
input := "MY=========" // Extra padding chars
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -120,7 +123,7 @@ test_base32_decode_invalid :: proc(t: ^testing.T) {
{
// Single character (invalid block)
input := "M"
output, err := decode(input)
output, err := base32.decode(input)
if output != nil {
defer delete(output)
}
@@ -141,9 +144,9 @@ test_base32_roundtrip :: proc(t: ^testing.T) {
}
for input in cases {
encoded := encode(transmute([]byte)input)
encoded := base32.encode(transmute([]byte)input)
defer delete(encoded)
decoded, err := decode(encoded)
decoded, err := base32.decode(encoded)
if decoded != nil {
defer delete(decoded)
}
@@ -188,7 +191,7 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
*/
custom_validate :: proc(c: byte) -> bool {
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V') || c == byte(PADDING)
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'V') || c == byte(base32.PADDING)
}
cases := [?]struct {
@@ -202,12 +205,12 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
for c in cases {
// Test encoding
encoded := encode(transmute([]byte)c.input, custom_enc_table)
encoded := base32.encode(transmute([]byte)c.input, custom_enc_table)
defer delete(encoded)
testing.expect(t, encoded == c.enc_expected)
// Test decoding
decoded, err := decode(encoded, custom_dec_table, custom_validate)
decoded, err := base32.decode(encoded, custom_dec_table, custom_validate)
defer if decoded != nil {
delete(decoded)
}
@@ -219,10 +222,10 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) {
// Test invalid character detection
{
input := "WXY=====" // Contains chars not in our alphabet
output, err := decode(input, custom_dec_table, custom_validate)
output, err := base32.decode(input, custom_dec_table, custom_validate)
if output != nil {
delete(output)
}
testing.expect_value(t, err, Error.Invalid_Character)
}
}
}

View File

@@ -13,6 +13,7 @@ download_assets :: proc "contextless" () {
@(require) import "c/libc"
@(require) import "compress"
@(require) import "container"
@(require) import "encoding/base32"
@(require) import "encoding/base64"
@(require) import "encoding/cbor"
@(require) import "encoding/hex"