Rename file names in search::matches to make it more clear.
This commit is contained in:
parent
ffec9578e6
commit
7b4b9edfe5
|
@ -58,7 +58,7 @@ void print_matches(const std::vector<search::match> &matches,
|
||||||
std::vector<std::string> metadata;
|
std::vector<std::string> metadata;
|
||||||
if (!opts.no_fn_epub)
|
if (!opts.no_fn_epub)
|
||||||
{
|
{
|
||||||
metadata.emplace_back(match.filepath);
|
metadata.emplace_back(match.filepath_inside);
|
||||||
}
|
}
|
||||||
if (!match.headline.empty())
|
if (!match.headline.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,8 +100,8 @@ std::vector<match> search(const fs::path &filepath,
|
||||||
boost::match_default))
|
boost::match_default))
|
||||||
{
|
{
|
||||||
match match; // FIXME: Rename variable or struct.
|
match match; // FIXME: Rename variable or struct.
|
||||||
match.epub_filepath = filepath;
|
match.filepath_epub = filepath;
|
||||||
match.filepath = entry;
|
match.filepath_inside = entry;
|
||||||
match.text = match_result[0];
|
match.text = match_result[0];
|
||||||
match.context = context(match_result, opts.context);
|
match.context = context(match_result, opts.context);
|
||||||
const auto current_headline{headline(match_result.prefix().str())};
|
const auto current_headline{headline(match_result.prefix().str())};
|
||||||
|
|
|
@ -35,12 +35,12 @@ using match_context = std::pair<std::string, std::string>;
|
||||||
|
|
||||||
struct match
|
struct match
|
||||||
{
|
{
|
||||||
fs::path epub_filepath; //!< File path of the EPUB.
|
fs::path filepath_epub; //!< File path of the EPUB.
|
||||||
std::string text; //!< Matched string.
|
std::string text; //!< Matched string.
|
||||||
match_context context; //!< The context around the match.
|
match_context context; //!< The context around the match.
|
||||||
std::string filepath; //!< The file path of the matched line.
|
std::string filepath_inside; //!< The file path of the matched line.
|
||||||
std::string headline; //!< The last headline, if available.
|
std::string headline; //!< The last headline, if available.
|
||||||
std::string page; //!< The page number, if available.
|
std::string page; //!< The page number, if available.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct settings
|
struct settings
|
||||||
|
|
|
@ -42,7 +42,7 @@ SCENARIO("Searching EPUB files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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(0).text == "test-file");
|
||||||
REQUIRE(matches.at(1).text == "test-suite");
|
REQUIRE(matches.at(1).text == "test-suite");
|
||||||
REQUIRE(matches.at(1).headline == "Test for epubgrep");
|
REQUIRE(matches.at(1).headline == "Test for epubgrep");
|
||||||
|
@ -66,16 +66,16 @@ SCENARIO("Searching EPUB files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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.first == "<a ");
|
||||||
REQUIRE(matches.at(0).context.second
|
REQUIRE(matches.at(0).context.second
|
||||||
== R"(="https://schlomp.space/tastytea/)"
|
== R"(="https://schlomp.space/tastytea/)"
|
||||||
R"(epubgrep">epubgrep</a>. Just)");
|
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.first == "<item ");
|
||||||
REQUIRE(matches.at(1).context.second
|
REQUIRE(matches.at(1).context.second
|
||||||
== R"(="start.xhtml" id="start")");
|
== 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.first == "<item ");
|
||||||
REQUIRE(matches.at(2).context.second
|
REQUIRE(matches.at(2).context.second
|
||||||
== R"(="toc.ncx" id="ncx")");
|
== R"(="toc.ncx" id="ncx")");
|
||||||
|
@ -116,7 +116,7 @@ SCENARIO("Searching EPUB files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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(0).text == "test-file");
|
||||||
REQUIRE(matches.at(1).text == "test-suite");
|
REQUIRE(matches.at(1).text == "test-suite");
|
||||||
REQUIRE(matches.at(1).headline == "Test for epubgrep");
|
REQUIRE(matches.at(1).headline == "Test for epubgrep");
|
||||||
|
@ -127,8 +127,8 @@ SCENARIO("Searching EPUB files works")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
opts.raw = 1;
|
opts.raw = true;
|
||||||
opts.context = 1;
|
opts.context = true;
|
||||||
matches = epubgrep::search::search(epubfile, "href", opts);
|
matches = epubgrep::search::search(epubfile, "href", opts);
|
||||||
}
|
}
|
||||||
catch (const std::exception &)
|
catch (const std::exception &)
|
||||||
|
@ -140,21 +140,21 @@ SCENARIO("Searching EPUB files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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.first == "<a ");
|
||||||
REQUIRE(matches.at(0).context.second
|
REQUIRE(matches.at(0).context.second
|
||||||
== R"(="https://schlomp.space/tastytea/)"
|
== R"(="https://schlomp.space/tastytea/)"
|
||||||
R"(epubgrep">epubgrep</a>. Just)");
|
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.first == "<li><a ");
|
||||||
REQUIRE(matches.at(1).context.second
|
REQUIRE(matches.at(1).context.second
|
||||||
== std::string(R"(="start.xhtml">Start</a></li>)")
|
== std::string(R"(="start.xhtml">Start</a></li>)")
|
||||||
+ "\n </ol>");
|
+ "\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.first == "<item ");
|
||||||
REQUIRE(matches.at(2).context.second
|
REQUIRE(matches.at(2).context.second
|
||||||
== R"(="start.xhtml" id="start")");
|
== 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.first == R"(id="nav" )");
|
||||||
REQUIRE(matches.at(3).context.second
|
REQUIRE(matches.at(3).context.second
|
||||||
== R"(="nav.xhtml" )"
|
== R"(="nav.xhtml" )"
|
||||||
|
|
|
@ -41,7 +41,7 @@ SCENARIO("Searching ZIP files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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).text == "📙");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ SCENARIO("Searching ZIP files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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).text == "📗");
|
||||||
REQUIRE(matches.at(0).context.first == "📖\n\n📘");
|
REQUIRE(matches.at(0).context.first == "📖\n\n📘");
|
||||||
REQUIRE(matches.at(0).context.second == "📙");
|
REQUIRE(matches.at(0).context.second == "📙");
|
||||||
|
@ -92,15 +92,16 @@ SCENARIO("Searching ZIP files works")
|
||||||
// TODO: Rewrite test.zip and tests to be better
|
// TODO: Rewrite test.zip and tests to be better
|
||||||
// understandable.
|
// understandable.
|
||||||
REQUIRE_FALSE(exception);
|
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).text == " ");
|
||||||
REQUIRE(matches.at(1).context.first == "don't");
|
REQUIRE(matches.at(1).context.first == "don't");
|
||||||
REQUIRE(matches.at(1).context.second == "want to");
|
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).text == "\n");
|
||||||
REQUIRE(matches.at(10).context.first == "📖");
|
REQUIRE(matches.at(10).context.first == "📖");
|
||||||
REQUIRE(matches.at(10).context.second == "\n📘📗📙");
|
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).text == "\n");
|
||||||
REQUIRE(matches.at(12).context.first == "📘📗📙");
|
REQUIRE(matches.at(12).context.first == "📘📗📙");
|
||||||
REQUIRE(matches.at(12).context.second.empty());
|
REQUIRE(matches.at(12).context.second.empty());
|
||||||
|
@ -126,7 +127,8 @@ SCENARIO("Searching ZIP files works")
|
||||||
AND_THEN("It returns the match correctly")
|
AND_THEN("It returns the match correctly")
|
||||||
{
|
{
|
||||||
REQUIRE_FALSE(exception);
|
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).text == "work today.\nI'm stay");
|
||||||
REQUIRE(matches.at(0).context.first == "to ");
|
REQUIRE(matches.at(0).context.first == "to ");
|
||||||
REQUIRE(matches.at(0).context.second == "ing in");
|
REQUIRE(matches.at(0).context.second == "ing in");
|
||||||
|
|
Loading…
Reference in New Issue