Merge branch 'develop' into main
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
commit
714cad1a53
|
@ -79,7 +79,7 @@ only.
|
||||||
|
|
||||||
* Tested OS: Linux
|
* Tested OS: Linux
|
||||||
* C++ compiler (tested: {uri-gcc}[gcc] 8/9, {uri-clang}[clang] 6/7)
|
* C++ compiler (tested: {uri-gcc}[gcc] 8/9, {uri-clang}[clang] 6/7)
|
||||||
* {uri-cmake}[cmake] (at least: 3.2)
|
* {uri-cmake}[cmake] (at least: 3.6)
|
||||||
* {uri-pkgconfig}[pkgconfig] (tested: 0.29)
|
* {uri-pkgconfig}[pkgconfig] (tested: 0.29)
|
||||||
* {uri-libxdg-basedir}[libxdg-basedir] (tested: 1.2)
|
* {uri-libxdg-basedir}[libxdg-basedir] (tested: 1.2)
|
||||||
* {uri-poco}[POCO] (tested: 1.9 / 1.7)
|
* {uri-poco}[POCO] (tested: 1.9 / 1.7)
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace remwharead
|
||||||
*
|
*
|
||||||
* @headerfile sqlite.hpp remwharead/sqlite.hpp
|
* @headerfile sqlite.hpp remwharead/sqlite.hpp
|
||||||
*/
|
*/
|
||||||
using entry = struct entry
|
struct entry
|
||||||
{
|
{
|
||||||
string uri;
|
string uri;
|
||||||
string archive_uri;
|
string archive_uri;
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace remwharead
|
||||||
*
|
*
|
||||||
* @headerfile uri.hpp remwharead/uri.hpp
|
* @headerfile uri.hpp remwharead/uri.hpp
|
||||||
*/
|
*/
|
||||||
using html_extract = struct html_extract
|
struct html_extract
|
||||||
{
|
{
|
||||||
bool successful = false;
|
bool successful = false;
|
||||||
string error;
|
string error;
|
||||||
|
@ -52,7 +52,7 @@ namespace remwharead
|
||||||
*
|
*
|
||||||
* @headerfile uri.hpp remwharead/uri.hpp
|
* @headerfile uri.hpp remwharead/uri.hpp
|
||||||
*/
|
*/
|
||||||
using archive_answer = struct archive_answer
|
struct archive_answer
|
||||||
{
|
{
|
||||||
bool successful = false;
|
bool successful = false;
|
||||||
string error;
|
string error;
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <regex>
|
||||||
|
#include <chrono>
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include "sqlite.hpp"
|
||||||
|
#include "export/json.hpp"
|
||||||
|
|
||||||
|
using namespace remwharead;
|
||||||
|
using std::string;
|
||||||
|
using std::chrono::system_clock;
|
||||||
|
using std::regex;
|
||||||
|
using std::regex_search;
|
||||||
|
|
||||||
|
SCENARIO ("The JSON export works correctly")
|
||||||
|
{
|
||||||
|
bool exception = false;
|
||||||
|
bool json_ok = true;
|
||||||
|
|
||||||
|
GIVEN ("One database entry")
|
||||||
|
{
|
||||||
|
Database::entry entry;
|
||||||
|
entry.uri = "https://example.com/page.html";
|
||||||
|
entry.tags = { "tag1", "tag2" };
|
||||||
|
entry.title = "Nice title";
|
||||||
|
entry.datetime = system_clock::time_point();
|
||||||
|
entry.fulltext = "Full text.";
|
||||||
|
entry.description = "Good description.";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::ostringstream output;
|
||||||
|
Export::JSON({ entry }, output).print();
|
||||||
|
const string json = output.str();
|
||||||
|
|
||||||
|
const regex re(
|
||||||
|
R"(^\[\{"archive_uri":"",)"
|
||||||
|
R"("datetime":"\d{4}(-\d{2}){2}T(\d{2}:){2}\d{2}",)"
|
||||||
|
R"("description":"Good description\.",)"
|
||||||
|
R"("fulltext":"Full text\.",)"
|
||||||
|
R"("tags":\["tag1","tag2"\],)"
|
||||||
|
R"("title":"Nice title",)"
|
||||||
|
R"("uri":"https:\\/\\/example\.com\\/page\.html"\}\]\n$)");
|
||||||
|
|
||||||
|
if (!regex_search(json, re))
|
||||||
|
{
|
||||||
|
json_ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
exception = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
THEN ("No exception is thrown")
|
||||||
|
AND_THEN ("Output looks okay")
|
||||||
|
{
|
||||||
|
REQUIRE_FALSE(exception);
|
||||||
|
REQUIRE(json_ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* This file is part of remwharead.
|
||||||
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <regex>
|
||||||
|
#include <chrono>
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include "sqlite.hpp"
|
||||||
|
#include "export/rss.hpp"
|
||||||
|
|
||||||
|
using namespace remwharead;
|
||||||
|
using std::string;
|
||||||
|
using std::chrono::system_clock;
|
||||||
|
using std::regex;
|
||||||
|
using std::regex_search;
|
||||||
|
|
||||||
|
SCENARIO ("The RSS export works correctly")
|
||||||
|
{
|
||||||
|
bool exception = false;
|
||||||
|
bool rss_ok = true;
|
||||||
|
|
||||||
|
GIVEN ("One database entry")
|
||||||
|
{
|
||||||
|
Database::entry entry;
|
||||||
|
entry.uri = "https://example.com/page.html";
|
||||||
|
entry.tags = { "tag1", "tag2" };
|
||||||
|
entry.title = "Nice title";
|
||||||
|
entry.datetime = system_clock::time_point();
|
||||||
|
entry.fulltext = "Full text.";
|
||||||
|
entry.description = "Good description.";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::ostringstream output;
|
||||||
|
Export::RSS({ entry }, output).print();
|
||||||
|
const string rss = output.str();
|
||||||
|
|
||||||
|
const regex re(
|
||||||
|
R"(^<rss version="2\.0" )"
|
||||||
|
R"(xmlns:atom="http://www\.w3\.org/2005/Atom"><channel>)"
|
||||||
|
R"(<title>Visited things</title><link/>)"
|
||||||
|
R"(<description>Export from remwharead\.</description>)"
|
||||||
|
R"(<generator>remwharead \d+\.\d+\.\d+</generator>)"
|
||||||
|
R"(<lastBuildDate>[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} )"
|
||||||
|
R"((\d{2}:){2}\d{2} [A-Z]+</lastBuildDate>)"
|
||||||
|
R"(<item><title>Nice title</title>)"
|
||||||
|
R"(<link>https://example\.com/page\.html</link>)"
|
||||||
|
R"(<guid isPermaLink="false">https://example\.com/page\.html )"
|
||||||
|
R"(at \d{4}(-\d{2}){2}T(\d{2}:){2}\d{2}</guid>)"
|
||||||
|
R"(<pubDate>[A-Z][a-z]{2}, \d{2} [A-Z][a-z]{2} \d{4} )"
|
||||||
|
R"((\d{2}:){2}\d{2} [A-Z]+</pubDate>)"
|
||||||
|
R"(<description><p>Good description\.</p>)"
|
||||||
|
R"(<p><strong>Tags:</strong> )"
|
||||||
|
R"(tag1, tag2</p></description>)"
|
||||||
|
R"(</item></channel></rss>\n$)");
|
||||||
|
|
||||||
|
if (!regex_search(rss, re))
|
||||||
|
{
|
||||||
|
rss_ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
exception = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
THEN ("No exception is thrown")
|
||||||
|
AND_THEN ("Output looks okay")
|
||||||
|
{
|
||||||
|
REQUIRE_FALSE(exception);
|
||||||
|
REQUIRE(rss_ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue