132 lines
2.8 KiB
C++
132 lines
2.8 KiB
C++
|
#include "cgi.cpp"
|
||
|
|
||
|
#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 = 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 = string_to_vector(str);
|
||
|
}
|
||
|
catch (std::exception &)
|
||
|
{
|
||
|
exception = true;
|
||
|
}
|
||
|
|
||
|
THEN("No exception is thrown")
|
||
|
AND_THEN(R"(vector is {})")
|
||
|
{
|
||
|
REQUIRE_FALSE(exception);
|
||
|
REQUIRE(vec == vector<string>());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
{
|
||
|
const string str{"a,b,"};
|
||
|
WHEN("string is \"" + str + '"')
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
vec = 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 = 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 = string_to_vector(str);
|
||
|
}
|
||
|
catch (std::exception &)
|
||
|
{
|
||
|
exception = true;
|
||
|
}
|
||
|
|
||
|
THEN("No exception is thrown")
|
||
|
AND_THEN(R"(vector is {})")
|
||
|
{
|
||
|
REQUIRE_FALSE(exception);
|
||
|
REQUIRE(vec == vector<string>());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} // namespace FediBlock
|