Add/move tests for helpers.
This commit is contained in:
parent
7ddfe32e30
commit
7f31d897cf
|
@ -0,0 +1,64 @@
|
||||||
|
#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]*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -70,33 +70,3 @@ SCENARIO("Zip file handling works")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SCENARIO("Helper functions in epubgrep::zip work")
|
|
||||||
{
|
|
||||||
SECTION("urldecode() doesn't fail and returns the decoded string")
|
|
||||||
{
|
|
||||||
bool exception{false};
|
|
||||||
|
|
||||||
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::zip::urldecode(encoded_text);
|
|
||||||
}
|
|
||||||
catch (const std::exception &)
|
|
||||||
{
|
|
||||||
exception = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
THEN("No exception is thrown")
|
|
||||||
AND_THEN("It returns the TOC correctly")
|
|
||||||
{
|
|
||||||
REQUIRE_FALSE(exception);
|
|
||||||
REQUIRE(decoded_text == "test folder/*file[test]*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue