This repository has been archived on 2021-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
backend/tests/test_string_to_vector.cpp

154 lines
3.3 KiB
C++

#include "cgi.hpp"
#include <catch.hpp>
#include <exception>
#include <string>
#include <vector>
namespace FediBlock
{
using std::string;
using std::vector;
SCENARIO("string_to_vector()")
{
bool exception{false};
vector<string> vec;
{
const string str{"a,b,c,d"};
WHEN("string is " + str)
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {"a", "b", "c", "d"})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec == vector<string>({"a", "b", "c", "d"}));
}
}
}
{
const string str;
WHEN("string is \"" + str + '"')
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec.empty());
}
}
}
{
const string str{"a,b,"};
WHEN("string is \"" + str + '"')
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {"a", "b"})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec == vector<string>({"a", "b"}));
}
}
}
{
const string str{",a,b"};
WHEN("string is \"" + str + '"')
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {"a", "b"})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec == vector<string>({"a", "b"}));
}
}
}
{
const string str{",,,"};
WHEN("string is \"" + str + '"')
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec.empty());
}
}
}
{
const string str{"a, b,c , d ,e"};
WHEN("string is \"" + str + '"')
{
try
{
vec = cgi::string_to_vector(str);
}
catch (std::exception &)
{
exception = true;
}
THEN("No exception is thrown")
AND_THEN(R"(vector is {"a", "b", "c", "d", "e"})")
{
REQUIRE_FALSE(exception);
REQUIRE(vec == vector<string>({"a", "b", "c", "d", "e"}));
}
}
}
}
} // namespace FediBlock