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() == '.'); + } + } } } }