epubgrep/tests/test_helpers.cpp

65 lines
1.6 KiB
C++

#include "fs-compat.hpp"
#include "helpers.hpp"
#include <catch.hpp>
#include <array>
#include <exception>
#include <string>
SCENARIO("Helpers work as intended")
{
bool exception{false};
bool result{false};
SECTION("is_whitespace() does what it should do")
{
for (const auto c : std::array{' ', '\n', '\r', '\t'})
{
WHEN(std::string("char is ") + c)
{
try
{
result = epubgrep::helpers::is_whitespace(c);
}
catch (const std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN("Whitespace is detected")
{
REQUIRE_FALSE(exception);
REQUIRE(result);
}
}
}
}
SECTION("urldecode() doesn't fail and returns the decoded string")
{
GIVEN("The string test%20folder/%2Afile%5Btest%5D%2A")
{
std::string encoded_text{"test%20folder/%2Afile%5Btest%5D%2A"};
std::string decoded_text{};
try
{
decoded_text = epubgrep::helpers::urldecode(encoded_text);
}
catch (const std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN("It returns the decoded text")
{
REQUIRE_FALSE(exception);
REQUIRE(decoded_text == "test folder/*file[test]*");
}
}
}
}