#include "catch.hpp" #include #include using namespace cpputils::hex; TEST_CASE("Hex conversion round-trip works", "[hex]") { std::string original = "Hello, World!"; std::string hex = toHex(original); std::string result = fromHex(hex); REQUIRE(result == original); } TEST_CASE("Empty string conversion", "[hex]") { std::string empty = ""; std::string hex = toHex(empty); std::string result = fromHex(hex); REQUIRE(hex.empty()); REQUIRE(result.empty()); } TEST_CASE("Single character conversion", "[hex]") { std::string single = "A"; std::string hex = toHex(single); std::string result = fromHex(hex); REQUIRE(result == single); } TEST_CASE("Non-printable ASCII characters", "[hex]") { std::string nonPrintable; for (char c = 0; c < 32; ++c) { nonPrintable += c; } std::string hex = toHex(nonPrintable); std::string result = fromHex(hex); REQUIRE(result == nonPrintable); } TEST_CASE("Extended ASCII characters", "[hex]") { std::string extended; for (unsigned char c = 128; c < 255; ++c) { extended += static_cast(c); } std::string hex = toHex(extended); std::string result = fromHex(hex); REQUIRE(result == extended); } TEST_CASE("Hex string with lowercase and uppercase letters", "[hex]") { std::string original = "abcABC123"; std::string hex = toHex(original); std::string result = fromHex(hex); REQUIRE(result == original); } TEST_CASE("Odd-length hex string should fail", "[hex]") { std::string invalidHex = "A"; REQUIRE(fromHex(invalidHex).empty()); } TEST_CASE("Hex string with invalid characters should fail", "[hex]") { std::string invalidHex = "ZZ"; REQUIRE(fromHex(invalidHex).empty()); } TEST_CASE("Large string conversion", "[hex]") { std::string large(10000, 'x'); std::string hex = toHex(large); std::string result = fromHex(hex); REQUIRE(result == large); }