Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
160 lines
5.4 KiB
C++
160 lines
5.4 KiB
C++
#include <Void/Text/Base64.hpp>
|
|
#include <Void/Text/Hex.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
// ── Base64 encode ─────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test base64_encode_empty()
|
|
{
|
|
Void::Testing::expect(Void::Encoding::Base64::encode("").empty());
|
|
}
|
|
|
|
Void::Testing::Test base64_encode_man()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Man"),
|
|
std::string{"TWFu"});
|
|
}
|
|
|
|
Void::Testing::Test base64_encode_ma()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Ma"),
|
|
std::string{"TWE="});
|
|
}
|
|
|
|
Void::Testing::Test base64_encode_m()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Base64::encode("M"),
|
|
std::string{"TQ=="});
|
|
}
|
|
|
|
Void::Testing::Test base64_encode_hello_world()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Base64::encode("Hello, World!"),
|
|
std::string{"SGVsbG8sIFdvcmxkIQ=="});
|
|
}
|
|
|
|
// ── Base64 decode ─────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test base64_decode_empty()
|
|
{
|
|
const auto r = Void::Encoding::Base64::decode("");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect(r->empty());
|
|
}
|
|
|
|
Void::Testing::Test base64_decode_man()
|
|
{
|
|
const auto r = Void::Encoding::Base64::decode("TWFu");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, std::string{"Man"});
|
|
}
|
|
|
|
Void::Testing::Test base64_decode_with_padding()
|
|
{
|
|
const auto r = Void::Encoding::Base64::decode("SGVsbG8sIFdvcmxkIQ==");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, std::string{"Hello, World!"});
|
|
}
|
|
|
|
Void::Testing::Test base64_decode_invalid_returns_nullopt()
|
|
{
|
|
const auto r = Void::Encoding::Base64::decode("!!");
|
|
Void::Testing::expect(!r.has_value());
|
|
}
|
|
|
|
Void::Testing::Test base64_round_trip()
|
|
{
|
|
const std::string original = "The quick brown fox jumps over the lazy dog";
|
|
const auto encoded = Void::Encoding::Base64::encode(original);
|
|
const auto decoded = Void::Encoding::Base64::decode(encoded);
|
|
Void::Testing::expect(decoded.has_value());
|
|
Void::Testing::expect_eq(*decoded, original);
|
|
}
|
|
|
|
// ── Base64 URL ────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test base64url_no_padding()
|
|
{
|
|
const auto s = Void::Encoding::Base64::encode_url("Man");
|
|
Void::Testing::expect_eq(s, std::string{"TWFu"});
|
|
Void::Testing::expect(s.find('=') == std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test base64url_no_plus_or_slash()
|
|
{
|
|
// encode something that would produce + or / in standard base64
|
|
const std::string tricky = "\xfb\xff\xfe";
|
|
const auto s = Void::Encoding::Base64::encode_url(tricky);
|
|
Void::Testing::expect(s.find('+') == std::string::npos);
|
|
Void::Testing::expect(s.find('/') == std::string::npos);
|
|
}
|
|
|
|
// ── Hex encode ───────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test hex_encode_empty()
|
|
{
|
|
Void::Testing::expect(Void::Encoding::Hex::encode("").empty());
|
|
}
|
|
|
|
Void::Testing::Test hex_encode_hello()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Hex::encode("Hi"),
|
|
std::string{"4869"});
|
|
}
|
|
|
|
Void::Testing::Test hex_encode_binary()
|
|
{
|
|
const std::string bin{'\x00', '\xff', '\xab'};
|
|
Void::Testing::expect_eq(Void::Encoding::Hex::encode(bin),
|
|
std::string{"00ffab"});
|
|
}
|
|
|
|
Void::Testing::Test hex_encode_upper()
|
|
{
|
|
Void::Testing::expect_eq(Void::Encoding::Hex::encode_upper("Hi"),
|
|
std::string{"4869"});
|
|
}
|
|
|
|
// ── Hex decode ───────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test hex_decode_empty()
|
|
{
|
|
const auto r = Void::Encoding::Hex::decode("");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect(r->empty());
|
|
}
|
|
|
|
Void::Testing::Test hex_decode_hello()
|
|
{
|
|
const auto r = Void::Encoding::Hex::decode("4869");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
|
}
|
|
|
|
Void::Testing::Test hex_decode_uppercase()
|
|
{
|
|
const auto r = Void::Encoding::Hex::decode("4869");
|
|
Void::Testing::expect(r.has_value());
|
|
Void::Testing::expect_eq(*r, std::string{"Hi"});
|
|
}
|
|
|
|
Void::Testing::Test hex_decode_odd_length_fails()
|
|
{
|
|
Void::Testing::expect(!Void::Encoding::Hex::decode("abc").has_value());
|
|
}
|
|
|
|
Void::Testing::Test hex_decode_invalid_char_fails()
|
|
{
|
|
Void::Testing::expect(!Void::Encoding::Hex::decode("zz").has_value());
|
|
}
|
|
|
|
Void::Testing::Test hex_round_trip()
|
|
{
|
|
const std::string original = "binary\x00\x01\x02\xff";
|
|
const auto encoded = Void::Encoding::Hex::encode(original);
|
|
const auto decoded = Void::Encoding::Hex::decode(encoded);
|
|
Void::Testing::expect(decoded.has_value());
|
|
Void::Testing::expect_eq(*decoded, original);
|
|
}
|