mirror of https://github.com/kiwix/libkiwix.git
Renamed some functions and variables
Included the word "Html" in the names of those functions and variables which will get Xml siblings soon.
This commit is contained in:
parent
75796ed6a5
commit
ed6aa5a89a
|
@ -528,7 +528,7 @@ const std::vector<SearchResult> LARGE_SEARCH_RESULTS = {
|
||||||
//
|
//
|
||||||
// 1. Snippets are excluded from the plain-text comparison of actual and
|
// 1. Snippets are excluded from the plain-text comparison of actual and
|
||||||
// expected HTML strings. This is done with the help of the
|
// expected HTML strings. This is done with the help of the
|
||||||
// function maskSnippetsInSearchResults()
|
// function maskSnippetsInHtmlSearchResults()
|
||||||
//
|
//
|
||||||
// 2. Snippets are checked separately. If a plain-text comparison fails
|
// 2. Snippets are checked separately. If a plain-text comparison fails
|
||||||
// then a weaker comparison is attempted. Currently it works by testing
|
// then a weaker comparison is attempted. Currently it works by testing
|
||||||
|
@ -546,7 +546,7 @@ const std::vector<SearchResult> LARGE_SEARCH_RESULTS = {
|
||||||
// - Non-overlapping snippets can be joined with a " ... " in between.
|
// - Non-overlapping snippets can be joined with a " ... " in between.
|
||||||
//
|
//
|
||||||
|
|
||||||
std::string maskSnippetsInSearchResults(std::string s)
|
std::string maskSnippetsInHtmlSearchResults(std::string s)
|
||||||
{
|
{
|
||||||
return replace(s, "<cite>.+</cite>", "<cite>SNIPPET TEXT WAS MASKED</cite>");
|
return replace(s, "<cite>.+</cite>", "<cite>SNIPPET TEXT WAS MASKED</cite>");
|
||||||
}
|
}
|
||||||
|
@ -645,7 +645,7 @@ struct TestData
|
||||||
return makeUrl(query, start, resultsPerPage);
|
return makeUrl(query, start, resultsPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string expectedHeader() const
|
std::string expectedHtmlHeader() const
|
||||||
{
|
{
|
||||||
if ( totalResultCount == 0 ) {
|
if ( totalResultCount == 0 ) {
|
||||||
return "\n No results were found for <b>\"" + getPattern() + "\"</b>";
|
return "\n No results were found for <b>\"" + getPattern() + "\"</b>";
|
||||||
|
@ -669,7 +669,7 @@ struct TestData
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string expectedResultsString() const
|
std::string expectedHtmlResultsString() const
|
||||||
{
|
{
|
||||||
if ( results.empty() ) {
|
if ( results.empty() ) {
|
||||||
return "\n ";
|
return "\n ";
|
||||||
|
@ -678,13 +678,13 @@ struct TestData
|
||||||
std::string s;
|
std::string s;
|
||||||
for ( const auto& r : results ) {
|
for ( const auto& r : results ) {
|
||||||
s += "\n <li>";
|
s += "\n <li>";
|
||||||
s += maskSnippetsInSearchResults(r.getHtml());
|
s += maskSnippetsInHtmlSearchResults(r.getHtml());
|
||||||
s += " </li>";
|
s += " </li>";
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string expectedFooter() const
|
std::string expectedHtmlFooter() const
|
||||||
{
|
{
|
||||||
if ( pagination.empty() ) {
|
if ( pagination.empty() ) {
|
||||||
return "\n ";
|
return "\n ";
|
||||||
|
@ -712,9 +712,9 @@ struct TestData
|
||||||
{
|
{
|
||||||
return makeSearchResultsHtml(
|
return makeSearchResultsHtml(
|
||||||
getPattern(),
|
getPattern(),
|
||||||
expectedHeader(),
|
expectedHtmlHeader(),
|
||||||
expectedResultsString(),
|
expectedHtmlResultsString(),
|
||||||
expectedFooter()
|
expectedHtmlFooter()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,17 +723,17 @@ struct TestData
|
||||||
return TestContext{ { "url", url() } };
|
return TestContext{ { "url", url() } };
|
||||||
}
|
}
|
||||||
|
|
||||||
void check(const std::string& html) const
|
void checkHtml(const std::string& html) const
|
||||||
{
|
{
|
||||||
EXPECT_EQ(maskSnippetsInSearchResults(html), expectedHtml())
|
EXPECT_EQ(maskSnippetsInHtmlSearchResults(html), expectedHtml())
|
||||||
<< testContext();
|
<< testContext();
|
||||||
|
|
||||||
checkSnippets(extractSearchResultSnippets(html));
|
checkSnippets(extractSearchResultSnippetsFromHtml(html));
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::vector<std::string> Snippets;
|
typedef std::vector<std::string> Snippets;
|
||||||
|
|
||||||
static Snippets extractSearchResultSnippets(const std::string& html)
|
static Snippets extractSearchResultSnippetsFromHtml(const std::string& html)
|
||||||
{
|
{
|
||||||
Snippets snippets;
|
Snippets snippets;
|
||||||
const std::regex snippetRegex("<cite>(.*)</cite>");
|
const std::regex snippetRegex("<cite>(.*)</cite>");
|
||||||
|
@ -1313,8 +1313,9 @@ TEST_F(ServerTest, searchResults)
|
||||||
};
|
};
|
||||||
|
|
||||||
for ( const auto& t : testData ) {
|
for ( const auto& t : testData ) {
|
||||||
const auto r = taskbarlessZimFileServer().GET(t.url().c_str());
|
const std::string htmlSearchUrl = t.url();
|
||||||
EXPECT_EQ(r->status, 200);
|
const auto htmlRes = taskbarlessZimFileServer().GET(htmlSearchUrl.c_str());
|
||||||
t.check(r->body);
|
EXPECT_EQ(htmlRes->status, 200);
|
||||||
|
t.checkHtml(htmlRes->body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue