1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-18 05:22:42 +01:00
Files
OpenRCT2/test/tests/StringTest.cpp
2017-12-25 00:30:21 +01:00

56 lines
1.5 KiB
C++
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <string>
#include <tuple>
#include <gtest/gtest.h>
#include <openrct2/core/String.hpp>
#include "AssertHelpers.hpp"
using TCase = std::tuple<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")
));
TEST_P(StringTest, Trim)
{
auto testCase = GetParam();
std::string input = std::get<0>(testCase);
std::string expected = std::get<1>(testCase);
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);
}