Text: add Void::Text base32 encode/decode facade (closes #49)

This commit is contained in:
faumaray committed 2026-12-03 16:33:06 +03:00
1 parent 62c2082fb3
commit f158d7b1cc
2 files changed
+69

No files matched your search

+32
View File
@@ -289,3 +289,35 @@ Void::Testing::Test base32_respects_text_limits()
Void::Testing::expect(
!decode_crockford("MZXW6YTB", TextLimits{.max_output = 4}).has_value());
}
// ── Void::Text facade ──────────────────────────────────────────────────────
Void::Testing::Test base32_text_facade_matches_encoding_namespace()
{
using Void::Text::base32_decode;
using Void::Text::base32_encode;
const std::array data{std::byte{'f'}, std::byte{'o'}, std::byte{'o'}};
const std::string padded =
base32_encode(std::span<const std::byte>{data});
Void::Testing::expect_eq(padded, std::string{"MZXW6==="});
Void::Testing::expect_eq(
base32_encode(std::span<const std::byte>{data}, false),
std::string{"MZXW6"});
const auto decoded = base32_decode(padded);
Void::Testing::require(decoded.has_value());
Void::Testing::expect_eq(*decoded, std::string{"foo"});
const auto decoded_unpadded = base32_decode(std::string_view{"MZXW6"});
Void::Testing::require(decoded_unpadded.has_value());
Void::Testing::expect_eq(*decoded_unpadded, std::string{"foo"});
const auto bytes = std::as_bytes(std::span{padded.data(), padded.size()});
const auto decoded_bytes = base32_decode(bytes);
Void::Testing::require(decoded_bytes.has_value());
Void::Testing::expect_eq(*decoded_bytes, std::string{"foo"});
Void::Testing::expect(!base32_decode(std::string_view{"MZXW6!"}).has_value());
Void::Testing::expect(!base32_decode(std::string_view{"MZXW6=="}).has_value());
}