diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2018-06-04 12:44:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-04 12:44:57 +0200 |
| commit | 8074192a85557feaf84d4aaab9ab42b02464220b (patch) | |
| tree | 397fdd6af48ef94001e5df65102495ea4b89139d /Source/UnitTests/Common/StringUtilTest.cpp | |
| parent | 472e0d55b807c7a5be847f113109ee4b38b48e80 (diff) | |
| parent | 7154bfd82559747681313531b5d53ab44bd88493 (diff) | |
Merge pull request #7057 from leoetlino/string
Config/StringUtil/IniFile: Get rid of some duplicated code
Diffstat (limited to 'Source/UnitTests/Common/StringUtilTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/StringUtilTest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp index 39a0d44944..cae007fdbe 100644 --- a/Source/UnitTests/Common/StringUtilTest.cpp +++ b/Source/UnitTests/Common/StringUtilTest.cpp @@ -84,3 +84,24 @@ TEST(StringUtil, UTF8ToSHIFTJIS) EXPECT_STREQ(SHIFTJISToUTF8(UTF8ToSHIFTJIS(kirby_unicode)).c_str(), kirby_unicode.c_str()); EXPECT_STREQ(UTF8ToSHIFTJIS(kirby_unicode).c_str(), kirby_sjis.c_str()); } + +template <typename T> +static void DoRoundTripTest(const std::vector<T>& data) +{ + for (const T& e : data) + { + const std::string s = ValueToString(e); + T out; + EXPECT_TRUE(TryParse(s, &out)); + EXPECT_EQ(e, out); + } +} + +TEST(StringUtil, ToString_TryParse_Roundtrip) +{ + DoRoundTripTest<bool>({true, false}); + DoRoundTripTest<int>({0, -1, 1, 123, -123, 123456789, -123456789}); + DoRoundTripTest<unsigned int>({0u, 1u, 123u, 123456789u, 4023456789u}); + DoRoundTripTest<float>({0.0f, 1.0f, -1.0f, -0.5f, 0.5f, -1e-3f, 1e-3f, 1e3f, -1e3f}); + DoRoundTripTest<double>({0.0, 1.0, -1.0, -0.5, 0.5, -1e-3, 1e-3, 1e3, -1e3}); +} |
