diff --git a/README.adoc b/README.adoc index d75a615..3f298fe 100644 --- a/README.adoc +++ b/README.adoc @@ -402,7 +402,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to * [x] Emoji * [x] Filter * [x] Instance -* [ ] List +* [x] List * [ ] Mention * [ ] Notification * [ ] Poll diff --git a/tests/entities/test_list.cpp b/tests/entities/test_list.cpp new file mode 100644 index 0000000..ecac49f --- /dev/null +++ b/tests/entities/test_list.cpp @@ -0,0 +1,82 @@ +/* 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/list.hpp" +#include "easy/easy.hpp" + +using std::string; +using std::chrono::system_clock; + +using namespace Mastodon; + +SCENARIO ("Easy::List works as intended", "[entity]") +{ + GIVEN ("An Easy::List object") + { + Easy::List list; + bool exception = false; + + WHEN ("It is initialized with valid list data") + { + const string data = + "{\"title\":\"testlist\",\"id\":\"1234\"}"; + + try + { + list.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("List is valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(list.valid()); + REQUIRE(list.id() == "1234"); + REQUIRE(list.title() == "testlist"); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + list.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(list.valid()); + REQUIRE(list.id() == ""); + } + } + } +}