From fe9555ec383356c9f095ea4ae3410f2d584b9fbc Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 21 Jul 2019 16:45:37 +0200 Subject: [PATCH] =?UTF-8?q?Added=20test=20for=20=E2=80=9Csimple=E2=80=9D?= =?UTF-8?q?=20export.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_simple.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/test_simple.cpp diff --git a/tests/test_simple.cpp b/tests/test_simple.cpp new file mode 100644 index 0000000..52b7ef8 --- /dev/null +++ b/tests/test_simple.cpp @@ -0,0 +1,72 @@ +/* This file is part of remwharead. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include "sqlite.hpp" +#include "simple.hpp" + +using std::string; +using std::chrono::system_clock; +using std::regex; +using std::regex_search; + +SCENARIO ("The Simple export works correctly") +{ + bool exception = false; + bool simple_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::Simple({ entry }, output).print(); + const string simple = output.str(); + + const regex re("[0-9]{4}-[0-9]{2}-[0-9]{2}: Nice title\n" + " {12}\n"); + + if (!regex_search(simple, re)) + { + simple_ok = false; + } + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Output looks okay") + { + REQUIRE_FALSE(exception); + REQUIRE(simple_ok); + } + } +}