mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Implement std::string variant of TrimStart; add tests.
This also makes String::TrimStart handle all-whitespace strings.
This commit is contained in:
committed by
Michael Steenbeek
parent
4bc2ad18c4
commit
d768a467b7
@@ -1,29 +1,31 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <gtest/gtest.h>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include "AssertHelpers.hpp"
|
||||
|
||||
using TCase = std::tuple<std::string, std::string>;
|
||||
using TCase = std::tuple<std::string, std::string, std::string>;
|
||||
|
||||
class StringTest : public testing::TestWithParam<TCase>
|
||||
{
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(TrimData, StringTest, testing::Values(
|
||||
TCase("string", "string"),
|
||||
TCase(" string", "string"),
|
||||
TCase("string ", "string"),
|
||||
TCase(" some string ", "some string"),
|
||||
TCase(" ", ""),
|
||||
TCase(" ストリング", "ストリング"),
|
||||
TCase("ストリング ", "ストリング"),
|
||||
TCase(" ストリング ", "ストリング"),
|
||||
TCase(" ", ""),
|
||||
TCase("", ""),
|
||||
TCase("\n", ""),
|
||||
TCase("\n\n\n\r\n", ""),
|
||||
TCase("\n\n\n\r\nstring\n\n", "string")
|
||||
// input after Trim after TrimStart
|
||||
TCase("string", "string", "string"),
|
||||
TCase(" string", "string", "string"),
|
||||
TCase("string ", "string", "string "),
|
||||
TCase(" some string ", "some string", "some string "),
|
||||
TCase(" ", "", ""),
|
||||
TCase(" ストリング", "ストリング", "ストリング"),
|
||||
TCase("ストリング ", "ストリング", "ストリング "),
|
||||
TCase(" ストリング ", "ストリング", "ストリング "),
|
||||
TCase(" ", "", ""),
|
||||
TCase("", "", ""),
|
||||
TCase("\n", "", ""),
|
||||
TCase("\n\n\n\r\n", "", ""),
|
||||
TCase("\n\n\n\r\nstring\n\n", "string", "string\n\n")
|
||||
));
|
||||
TEST_P(StringTest, Trim)
|
||||
{
|
||||
@@ -34,6 +36,15 @@ TEST_P(StringTest, Trim)
|
||||
ASSERT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
TEST_P(StringTest, TrimStart)
|
||||
{
|
||||
auto testCase = GetParam();
|
||||
std::string input = std::get<0>(testCase);
|
||||
std::string expected = std::get<2>(testCase);
|
||||
std::string actual = String::TrimStart(input);
|
||||
ASSERT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
TEST_F(StringTest, Split_ByComma)
|
||||
{
|
||||
auto actual = String::Split("a,bb,ccc,dd", ",");
|
||||
|
||||
Reference in New Issue
Block a user