2020-07-01 20:51:35 +02:00
|
|
|
#include "cgi.hpp"
|
2020-06-30 07:32:02 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
vec = cgi::string_to_vector(str);
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
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"}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
const string str;
|
2020-06-30 07:32:02 +02:00
|
|
|
WHEN("string is \"" + str + '"')
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
vec = cgi::string_to_vector(str);
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
catch (std::exception &)
|
|
|
|
{
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
THEN("No exception is thrown")
|
|
|
|
AND_THEN(R"(vector is {})")
|
|
|
|
{
|
|
|
|
REQUIRE_FALSE(exception);
|
2020-07-01 20:51:35 +02:00
|
|
|
REQUIRE(vec.empty());
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const string str{"a,b,"};
|
|
|
|
WHEN("string is \"" + str + '"')
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
vec = cgi::string_to_vector(str);
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
vec = cgi::string_to_vector(str);
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2020-07-01 20:51:35 +02:00
|
|
|
vec = cgi::string_to_vector(str);
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
catch (std::exception &)
|
|
|
|
{
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
THEN("No exception is thrown")
|
|
|
|
AND_THEN(R"(vector is {})")
|
|
|
|
{
|
|
|
|
REQUIRE_FALSE(exception);
|
2020-07-01 20:51:35 +02:00
|
|
|
REQUIRE(vec.empty());
|
2020-06-30 07:32:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace FediBlock
|