From bbac2b7c51978781e948a1dacbfee9a2c698e60e Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 10 Jun 2019 17:22:22 +0200 Subject: [PATCH] Added tests for Easy::Mention. --- README.adoc | 2 +- tests/entities/test_mention.cpp | 88 +++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/entities/test_mention.cpp diff --git a/README.adoc b/README.adoc index 3f298fe..98848b7 100644 --- a/README.adoc +++ b/README.adoc @@ -403,7 +403,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to * [x] Filter * [x] Instance * [x] List -* [ ] Mention +* [x] Mention * [ ] Notification * [ ] Poll * [ ] PushSubscription diff --git a/tests/entities/test_mention.cpp b/tests/entities/test_mention.cpp new file mode 100644 index 0000000..17a4137 --- /dev/null +++ b/tests/entities/test_mention.cpp @@ -0,0 +1,88 @@ +/* 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/mention.hpp" +#include "easy/easy.hpp" + +using std::string; +using std::chrono::system_clock; + +using namespace Mastodon; + +SCENARIO ("Easy::Mention works as intended", "[entity]") +{ + GIVEN ("An Easy::Mention object") + { + Easy::Mention mention; + bool exception = false; + + WHEN ("It is initialized with valid mention data") + { + const string data = + "{\"acct\" : \"testaccount\"," + "\"url\" : \"https://likeable.space/users/testaccount\"," + " \"username\" : \"testaccount\"," + " \"id\" : \"9fQhcoI95ZdmNasg0e\"}"; + + try + { + mention.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Mention is valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(mention.valid()); + REQUIRE(mention.id() == "9fQhcoI95ZdmNasg0e"); + REQUIRE(mention.acct() == "testaccount"); + REQUIRE(mention.username() == "testaccount"); + REQUIRE(mention.url() == + "https://likeable.space/users/testaccount"); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + mention.from_string(""); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("It is not valid") + AND_THEN ("id is empty") + { + REQUIRE_FALSE(exception); + REQUIRE_FALSE(mention.valid()); + REQUIRE(mention.id() == ""); + } + } + } +}