#define CATCH_CONFIG_MAIN
#include <catch2/catch_test_macros.hpp>
#include <curl/curl.h>
namespace {
std::string cmp_escape(std::string_view src)
{
std::string ret;
if (auto curl = curl_easy_init())
{
if (auto output = curl_easy_escape(curl, src.data(), int(src.size())))
{
ret = output;
curl_free(output);
}
curl_easy_cleanup(curl);
}
return ret;
}
#if 0
std::string cmp_unescape(std::string_view src)
{
std::string ret;
if (auto curl = curl_easy_init())
{
int decodelen;
if (auto p = curl_easy_unescape(curl, src.data(), int(src.size()), &decodelen))
{
ret.assign(p, decodelen);
curl_free(p);
}
curl_easy_cleanup(curl);
}
return ret;
}
#endif
void escape_roundtrip(std::string_view s)
{
CHECK(t == cmp_escape(s));
}
}
using namespace std::literals;
TEST_CASE("Zero char", "[Z]")
{
escape_roundtrip({});
}
TEST_CASE("One char ok", "[O][B]")
{
for (auto i: {"1"sv, "a"sv, "Z"sv, "%"sv, "_"sv, "\n"sv, "\r"sv, "\t"sv, "\xff"sv, {"\0",1}})
escape_roundtrip(i);
}
TEST_CASE("One char exception", "[O][E]")
{
}
TEST_CASE("Sentence & paragraphs", "[M][S]")
{
escape_roundtrip("Hello world!!!"sv);
escape_roundtrip("廢宅世界歡迎你 🙏"sv);
}
std::string easy_escape(std::string_view src)
std::string easy_unescape(std::string_view src)