Rename file names in search::matches to make it more clear.

This commit is contained in:
tastytea 2021-06-01 19:15:00 +02:00
parent ffec9578e6
commit 7b4b9edfe5
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 28 additions and 26 deletions

View File

@ -58,7 +58,7 @@ void print_matches(const std::vector<search::match> &matches,
std::vector<std::string> metadata;
if (!opts.no_fn_epub)
{
metadata.emplace_back(match.filepath);
metadata.emplace_back(match.filepath_inside);
}
if (!match.headline.empty())
{

View File

@ -100,8 +100,8 @@ std::vector<match> search(const fs::path &filepath,
boost::match_default))
{
match match; // FIXME: Rename variable or struct.
match.epub_filepath = filepath;
match.filepath = entry;
match.filepath_epub = filepath;
match.filepath_inside = entry;
match.text = match_result[0];
match.context = context(match_result, opts.context);
const auto current_headline{headline(match_result.prefix().str())};

View File

@ -35,12 +35,12 @@ using match_context = std::pair<std::string, std::string>;
struct match
{
fs::path epub_filepath; //!< File path of the EPUB.
std::string text; //!< Matched string.
match_context context; //!< The context around the match.
std::string filepath; //!< The file path of the matched line.
std::string headline; //!< The last headline, if available.
std::string page; //!< The page number, if available.
fs::path filepath_epub; //!< File path of the EPUB.
std::string text; //!< Matched string.
match_context context; //!< The context around the match.
std::string filepath_inside; //!< The file path of the matched line.
std::string headline; //!< The last headline, if available.
std::string page; //!< The page number, if available.
};
struct settings

View File

@ -42,7 +42,7 @@ SCENARIO("Searching EPUB files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "start.xhtml");
REQUIRE(matches.at(0).filepath_inside == "start.xhtml");
REQUIRE(matches.at(0).text == "test-file");
REQUIRE(matches.at(1).text == "test-suite");
REQUIRE(matches.at(1).headline == "Test for epubgrep");
@ -66,16 +66,16 @@ SCENARIO("Searching EPUB files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "start.xhtml");
REQUIRE(matches.at(0).filepath_inside == "start.xhtml");
REQUIRE(matches.at(0).context.first == "<a ");
REQUIRE(matches.at(0).context.second
== R"(="https://schlomp.space/tastytea/)"
R"(epubgrep">epubgrep</a>. Just)");
REQUIRE(matches.at(1).filepath == "metadata.opf");
REQUIRE(matches.at(1).filepath_inside == "metadata.opf");
REQUIRE(matches.at(1).context.first == "<item ");
REQUIRE(matches.at(1).context.second
== R"(="start.xhtml" id="start")");
REQUIRE(matches.at(2).filepath == "metadata.opf");
REQUIRE(matches.at(2).filepath_inside == "metadata.opf");
REQUIRE(matches.at(2).context.first == "<item ");
REQUIRE(matches.at(2).context.second
== R"(="toc.ncx" id="ncx")");
@ -116,7 +116,7 @@ SCENARIO("Searching EPUB files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "start.xhtml");
REQUIRE(matches.at(0).filepath_inside == "start.xhtml");
REQUIRE(matches.at(0).text == "test-file");
REQUIRE(matches.at(1).text == "test-suite");
REQUIRE(matches.at(1).headline == "Test for epubgrep");
@ -127,8 +127,8 @@ SCENARIO("Searching EPUB files works")
{
try
{
opts.raw = 1;
opts.context = 1;
opts.raw = true;
opts.context = true;
matches = epubgrep::search::search(epubfile, "href", opts);
}
catch (const std::exception &)
@ -140,21 +140,21 @@ SCENARIO("Searching EPUB files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "start.xhtml");
REQUIRE(matches.at(0).filepath_inside == "start.xhtml");
REQUIRE(matches.at(0).context.first == "<a ");
REQUIRE(matches.at(0).context.second
== R"(="https://schlomp.space/tastytea/)"
R"(epubgrep">epubgrep</a>. Just)");
REQUIRE(matches.at(1).filepath == "nav.xhtml");
REQUIRE(matches.at(1).filepath_inside == "nav.xhtml");
REQUIRE(matches.at(1).context.first == "<li><a ");
REQUIRE(matches.at(1).context.second
== std::string(R"(="start.xhtml">Start</a></li>)")
+ "\n </ol>");
REQUIRE(matches.at(2).filepath == "metadata.opf");
REQUIRE(matches.at(2).filepath_inside == "metadata.opf");
REQUIRE(matches.at(2).context.first == "<item ");
REQUIRE(matches.at(2).context.second
== R"(="start.xhtml" id="start")");
REQUIRE(matches.at(3).filepath == "metadata.opf");
REQUIRE(matches.at(3).filepath_inside == "metadata.opf");
REQUIRE(matches.at(3).context.first == R"(id="nav" )");
REQUIRE(matches.at(3).context.second
== R"(="nav.xhtml" )"

View File

@ -41,7 +41,7 @@ SCENARIO("Searching ZIP files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "test folder/😊");
REQUIRE(matches.at(0).filepath_inside == "test folder/😊");
REQUIRE(matches.at(0).text == "📙");
}
}
@ -62,7 +62,7 @@ SCENARIO("Searching ZIP files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "test folder/😊");
REQUIRE(matches.at(0).filepath_inside == "test folder/😊");
REQUIRE(matches.at(0).text == "📗");
REQUIRE(matches.at(0).context.first == "📖\n\n📘");
REQUIRE(matches.at(0).context.second == "📙");
@ -92,15 +92,16 @@ SCENARIO("Searching ZIP files works")
// TODO: Rewrite test.zip and tests to be better
// understandable.
REQUIRE_FALSE(exception);
REQUIRE(matches.at(1).filepath == "test folder/test file");
REQUIRE(matches.at(1).filepath_inside
== "test folder/test file");
REQUIRE(matches.at(1).text == " ");
REQUIRE(matches.at(1).context.first == "don't");
REQUIRE(matches.at(1).context.second == "want to");
REQUIRE(matches.at(10).filepath == "test folder/😊");
REQUIRE(matches.at(10).filepath_inside == "test folder/😊");
REQUIRE(matches.at(10).text == "\n");
REQUIRE(matches.at(10).context.first == "📖");
REQUIRE(matches.at(10).context.second == "\n📘📗📙");
REQUIRE(matches.at(12).filepath == "test folder/😊");
REQUIRE(matches.at(12).filepath_inside == "test folder/😊");
REQUIRE(matches.at(12).text == "\n");
REQUIRE(matches.at(12).context.first == "📘📗📙");
REQUIRE(matches.at(12).context.second.empty());
@ -126,7 +127,8 @@ SCENARIO("Searching ZIP files works")
AND_THEN("It returns the match correctly")
{
REQUIRE_FALSE(exception);
REQUIRE(matches.at(0).filepath == "test folder/test file");
REQUIRE(matches.at(0).filepath_inside
== "test folder/test file");
REQUIRE(matches.at(0).text == "work today.\nI'm stay");
REQUIRE(matches.at(0).context.first == "to ");
REQUIRE(matches.at(0).context.second == "ing in");