aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/strings.cpp
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2020-05-19 15:05:53 -0700
committerGitHub <noreply@github.com>2020-05-19 15:05:53 -0700
commit0116b86e38517d9f430e150feb19914915b734da (patch)
treef6bedf9495cb807a9f9d5f75daa0a76bfd7d1ae6 /toolsrc/src/vcpkg-test/strings.cpp
parent9a0652b87002b671a3dd90038461f912d368a398 (diff)
downloadvcpkg-0116b86e38517d9f430e150feb19914915b734da.tar.gz
vcpkg-0116b86e38517d9f430e150feb19914915b734da.zip
[vcpkg] Optimize string split slightly. (#11433)
Diffstat (limited to 'toolsrc/src/vcpkg-test/strings.cpp')
-rw-r--r--toolsrc/src/vcpkg-test/strings.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/toolsrc/src/vcpkg-test/strings.cpp b/toolsrc/src/vcpkg-test/strings.cpp
index d58d1b172..eb1f5697f 100644
--- a/toolsrc/src/vcpkg-test/strings.cpp
+++ b/toolsrc/src/vcpkg-test/strings.cpp
@@ -2,15 +2,16 @@
#include <vcpkg/base/strings.h>
-#include <cstdint>
+#include <stdint.h>
#include <utility>
#include <vector>
+#include <string>
TEST_CASE ("b32 encoding", "[strings]")
{
- using u64 = std::uint64_t;
+ using u64 = uint64_t;
- std::vector<std::pair<std::uint64_t, std::string>> map;
+ std::vector<std::pair<u64, std::string>> map;
map.emplace_back(0, "AAAAAAAAAAAAA");
map.emplace_back(1, "BAAAAAAAAAAAA");
@@ -24,10 +25,19 @@ TEST_CASE ("b32 encoding", "[strings]")
map.emplace_back(0x1405'64E7'FE7E'A88C, "MEK5H774ELBIB");
map.emplace_back(0xFFFF'FFFF'FFFF'FFFF, "777777777777P");
- std::string result;
for (const auto& pr : map)
{
- result = vcpkg::Strings::b32_encode(pr.first);
REQUIRE(vcpkg::Strings::b32_encode(pr.first) == pr.second);
}
}
+
+TEST_CASE ("split by char", "[strings]")
+{
+ using vcpkg::Strings::split;
+ using result_t = std::vector<std::string>;
+ REQUIRE(split(",,,,,,", ',').empty());
+ REQUIRE(split(",,a,,b,,", ',') == result_t{"a", "b"});
+ REQUIRE(split("hello world", ' ') == result_t{"hello", "world"});
+ REQUIRE(split(" hello world ", ' ') == result_t{"hello", "world"});
+ REQUIRE(split("no delimiters", ',') == result_t{"no delimiters"});
+}