Added tests for searching.
This commit is contained in:
parent
2ebd27b159
commit
9d47444761
95
tests/test_search.cpp
Normal file
95
tests/test_search.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/* 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 <chrono>
|
||||
#include <vector>
|
||||
#include <catch.hpp>
|
||||
#include "sqlite.hpp"
|
||||
#include "search.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::chrono::system_clock;
|
||||
using std::vector;
|
||||
|
||||
SCENARIO ("Searching works correctly")
|
||||
{
|
||||
bool exception = false;
|
||||
bool search_ok = true;
|
||||
|
||||
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.";
|
||||
|
||||
WHEN ("Searching in tags")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (search_tags({ entry }, "tAg1_ö", false).size() != 1)
|
||||
{
|
||||
search_ok = false;
|
||||
}
|
||||
|
||||
if (search_tags({ entry }, "tAg?[0-9]_ö", true).size() != 1)
|
||||
{
|
||||
search_ok = false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
THEN ("No exception is thrown")
|
||||
AND_THEN ("Results look okay")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
REQUIRE(search_ok);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN ("Searching in everything")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (search_all({ entry }, "DESCRIPT AND good", false).size() != 1)
|
||||
{
|
||||
search_ok = false;
|
||||
}
|
||||
|
||||
if (search_all({ entry }, "^ful{2} T..T\\.$", true).size() != 1)
|
||||
{
|
||||
search_ok = false;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
exception = true;
|
||||
}
|
||||
|
||||
THEN ("No exception is thrown")
|
||||
AND_THEN ("Results look okay")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
REQUIRE(search_ok);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user