From 4ac61852edd98348128aa37e991d9f0cc0939d87 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 28 Nov 2019 09:22:03 +0100 Subject: [PATCH] Add test for rofi export. --- tests/test_rofi.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/test_rofi.cpp diff --git a/tests/test_rofi.cpp b/tests/test_rofi.cpp new file mode 100644 index 0000000..fdd3d25 --- /dev/null +++ b/tests/test_rofi.cpp @@ -0,0 +1,68 @@ +/* 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 "sqlite.hpp" +#include "export/rofi.hpp" + +using namespace remwharead; +using std::string; + +SCENARIO ("The Rofi export works correctly") +{ + bool exception = false; + bool rofi_ok = true; + + GIVEN ("One database entry") + { + Database::entry entry; + entry.uri = "https://example.com/page.html"; + entry.title = "Thoughtful title"; + entry.tags = { "tag1", "tag2" }; + + const string expected = static_cast(0x00) + string("markup-rows") + + static_cast(0x1f) + "true\n" + "Thoughtful title " + R"((tag1,tag2))" + R"( )" + "https://example.com/page.html\n"; + + try + { + std::ostringstream output; + Export::Rofi({ entry }, output).print(); + const string rofi = output.str(); + + if (rofi != expected) + { + rofi_ok = false; + } + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Output looks okay") + { + REQUIRE_FALSE(exception); + REQUIRE(rofi_ok); + } + } +}