stuff-from-scratch/test/core/TestStringUtils.cpp

31 lines
888 B
C++
Raw Normal View History

2022-12-05 17:50:49 +00:00
#include "StringUtils.h"
#include "TestFramework.h"
#include "TestUtils.h"
2022-12-06 18:02:43 +00:00
TEST_CASE(TestStringUtils_StripSurroundingWhitepsace, "core")
2022-12-05 17:50:49 +00:00
{
std::string input = " super() ";
2022-12-06 18:02:43 +00:00
std::string stripped = StringUtils::stripSurroundingWhitepsace(input);
REQUIRE(stripped == "super()");
}
TEST_CASE(TestStringUtils_RemoveUpTo, "core")
{
std::string input = "def{filename}abc/123/456";
std::string removed = StringUtils::removeUpTo(input, "{filename}");
REQUIRE(removed == "abc/123/456");
}
TEST_CASE(TestStringUtils_startsWith, "core")
{
std::string input = " ```some triple ticks ";
bool ignore_whitespace{false};
auto starts_with = StringUtils::startsWith(input, "```", ignore_whitespace);
REQUIRE(!starts_with);
2022-12-05 17:50:49 +00:00
2022-12-06 18:02:43 +00:00
ignore_whitespace = true;
starts_with = StringUtils::startsWith(input, "```", ignore_whitespace);
REQUIRE(starts_with);
2022-12-05 17:50:49 +00:00
}