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++
Raw Normal View History

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
}
}
}
2020-07-14 17:30:36 +02:00
{
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);
2020-07-14 17:55:35 +02:00
REQUIRE(vec == vector<string>({"a", "b", "c", "d", "e"}));
2020-07-14 17:30:36 +02:00
}
}
}
2020-06-30 07:32:02 +02:00
}
} // namespace FediBlock