From 1c8279f96f8c0f20f77b73dac595952d4bc7a744 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 7 Jun 2021 00:05:33 +0200 Subject: [PATCH] Add test that asks for more context than is available. --- tests/test_search_epub.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/test_search_epub.cpp b/tests/test_search_epub.cpp index 2efa990..e11cc6b 100644 --- a/tests/test_search_epub.cpp +++ b/tests/test_search_epub.cpp @@ -88,8 +88,7 @@ SCENARIO("Searching EPUB files works") GIVEN("Our test EPUB3 file") { fs::path epubfile{"test.epub3"}; - std::setlocale(LC_CTYPE, - ""); // Needed for utf-8 support in libarchive. + std::setlocale(LC_CTYPE, ""); // Needed for utf-8 support in libarchive. bool exception{false}; REQUIRE(fs::exists(epubfile)); @@ -161,6 +160,32 @@ SCENARIO("Searching EPUB files works") R"(media-type="application/xhtml+xml")"); } } + + WHEN("We search for for a phrase at the beginning of the file " + "and specify a very high context") + { + try + { + opts.context = 69069; + matches = epubgrep::search::search(epubfile, "Test for", + opts); + } + catch (const std::exception &) + { + exception = true; + } + + THEN("No exception is thrown") + AND_THEN("It returns the match correctly") + { + REQUIRE_FALSE(exception); + REQUIRE(matches.at(0).filepath_inside == "start.xhtml"); + REQUIRE(matches.at(0).text == "Test for"); + REQUIRE(matches.at(0).headline.empty()); + REQUIRE(matches.at(0).context.first.empty()); + REQUIRE(*matches.at(0).context.second.rbegin() == '.'); + } + } } } }