mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-16 04:22:43 +01:00
Improve String::Split and add tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <tuple>
|
||||
#include <gtest/gtest.h>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include "AssertHelpers.hpp"
|
||||
|
||||
using TCase = std::tuple<std::string, std::string>;
|
||||
|
||||
@@ -28,3 +29,23 @@ TEST_P(StringTest, Trim)
|
||||
std::string actual = String::Trim(input);
|
||||
ASSERT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
TEST_F(StringTest, Split_ByComma)
|
||||
{
|
||||
auto actual = String::Split("a,bb,ccc,dd", ",");
|
||||
AssertVector<std::string>(actual, { "a", "bb", "ccc", "dd" });
|
||||
}
|
||||
TEST_F(StringTest, Split_ByColonColon)
|
||||
{
|
||||
auto actual = String::Split("a::bb:ccc:::::dd", "::");
|
||||
AssertVector<std::string>(actual, { "a", "bb:ccc", "", ":dd" });
|
||||
}
|
||||
TEST_F(StringTest, Split_Empty)
|
||||
{
|
||||
auto actual = String::Split("", ".");
|
||||
AssertVector<std::string>(actual, { });
|
||||
}
|
||||
TEST_F(StringTest, Split_ByEmpty)
|
||||
{
|
||||
EXPECT_THROW(String::Split("string", ""), std::invalid_argument);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user