diff options
| author | Martin Ridgers <[email protected]> | 2021-09-21 11:06:13 +0200 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-09-21 11:06:13 +0200 |
| commit | 68c951e0f440ffd483795dced737e88152c1a581 (patch) | |
| tree | 5c0910ca2a85b45fb05dba3ce457b7d156213894 /zencore/string.cpp | |
| parent | Merge main into linux-mac (diff) | |
| parent | Trigger storage scrubbing pass at startup (diff) | |
| download | zen-68c951e0f440ffd483795dced737e88152c1a581.tar.xz zen-68c951e0f440ffd483795dced737e88152c1a581.zip | |
Merged main into linux-mac
Diffstat (limited to 'zencore/string.cpp')
| -rw-r--r-- | zencore/string.cpp | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/zencore/string.cpp b/zencore/string.cpp index 8ea10d2a3..6dcdc9542 100644 --- a/zencore/string.cpp +++ b/zencore/string.cpp @@ -1,11 +1,12 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <doctest/doctest.h> +#include <zencore/memory.h> +#include <zencore/string.h> +#include <zencore/testing.h> + #include <inttypes.h> #include <math.h> #include <stdio.h> -#include <zencore/memory.h> -#include <zencore/string.h> #include <exception> #include <ostream> #include <stdexcept> @@ -452,6 +453,8 @@ template class StringBuilderImpl<wchar_t>; // Unit tests // +#if ZEN_WITH_TESTS + TEST_CASE("niceNum") { char Buffer[16]; @@ -912,4 +915,46 @@ TEST_CASE("filepath") CHECK(FilepathFindExtension(".txt") == std::string_view(".txt")); } +TEST_CASE("string") +{ + using namespace std::literals; + + SUBCASE("ForEachStrTok") + { + const auto Tokens = "here,is,my,different,tokens"sv; + int32_t ExpectedTokenCount = 5; + int32_t TokenCount = 0; + StringBuilder<512> Sb; + + TokenCount = ForEachStrTok(Tokens, ',', [&Sb](const std::string_view& Token) { + if (Sb.Size()) + { + Sb << ","; + } + Sb << Token; + return true; + }); + + CHECK(TokenCount == ExpectedTokenCount); + CHECK(Sb.ToString() == Tokens); + + ExpectedTokenCount = 1; + const auto Str = "mosdef"sv; + + Sb.Reset(); + TokenCount = ForEachStrTok(Str, ' ', [&Sb](const std::string_view& Token) { + Sb << Token; + return true; + }); + CHECK(Sb.ToString() == Str); + CHECK(TokenCount == ExpectedTokenCount); + + ExpectedTokenCount = 0; + TokenCount = ForEachStrTok(""sv, ',', [](const std::string_view&) { return true; }); + CHECK(TokenCount == ExpectedTokenCount); + } +} + +#endif + } // namespace zen |