From c49518981b3a8576508f80961e80223f0abc736b Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 12 Aug 2019 05:49:56 +0200 Subject: [PATCH] Added tests for Easy::Tag. --- README.adoc | 2 +- tests/entities/test_tag.cpp | 85 +++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/entities/test_tag.cpp diff --git a/README.adoc b/README.adoc index 1664e77..90dde12 100644 --- a/README.adoc +++ b/README.adoc @@ -412,7 +412,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to * [x] Results * [x] Status * [ ] ScheduledStatus -* [ ] Tag +* [x] Tag * [ ] Token === glitch-soc API diff --git a/tests/entities/test_tag.cpp b/tests/entities/test_tag.cpp new file mode 100644 index 0000000..ced7146 --- /dev/null +++ b/tests/entities/test_tag.cpp @@ -0,0 +1,85 @@ +/* This file is part of mastodon-cpp. + * 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 "easy/entities/tag.hpp" +#include "easy/easy.hpp" + +using std::string; +using std::chrono::system_clock; + +using namespace Mastodon; + +SCENARIO ("Easy::Tag works as intended", "[entity]") +{ + GIVEN ("An Easy::Tag object") + { + Easy::Tag tag; + bool exception = false; + + WHEN ("It is initialized with valid tag data") + { + const string data = + "{\"name\":\"testtag\"," + "\"url\":\"https://example.com/tag/testtag\"," + "\"history\":" + "[{\"day\":\"1565579400\",\"uses\":4,\"accounts\":2}]}"; + + try + { + tag.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Tag are valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(tag.valid()); + REQUIRE(tag.name() == "testtag"); + REQUIRE(tag.history()[0].uses() == 4); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + tag.from_string(""); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("It is not valid") + AND_THEN ("history is empty") + { + REQUIRE_FALSE(exception); + REQUIRE_FALSE(tag.valid()); + REQUIRE(tag.history().size() == 0); + } + } + } +}