#include "cgi.hpp" #include #include #include #include namespace FediBlock { using std::string; using std::vector; SCENARIO("string_to_vector()") { bool exception{false}; vector 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({"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({"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({"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({"a", "b", "c", "d", "e"})); } } } } } // namespace FediBlock