From 7f31d897cf52d42301e04abe52daac3b56eac51e Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 30 May 2021 22:22:24 +0200 Subject: [PATCH] Add/move tests for helpers. --- tests/test_helpers.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++ tests/test_zip.cpp | 30 -------------------- 2 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 tests/test_helpers.cpp diff --git a/tests/test_helpers.cpp b/tests/test_helpers.cpp new file mode 100644 index 0000000..68c2f2d --- /dev/null +++ b/tests/test_helpers.cpp @@ -0,0 +1,64 @@ +#include "fs-compat.hpp" +#include "helpers.hpp" + +#include + +#include +#include +#include + +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]*"); + } + } + } +} diff --git a/tests/test_zip.cpp b/tests/test_zip.cpp index dd067ed..ad9ede4 100644 --- a/tests/test_zip.cpp +++ b/tests/test_zip.cpp @@ -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]*"); - } - } - } -}