aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test/strings.cpp
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2020-12-21 09:19:57 -0800
committerGitHub <noreply@github.com>2020-12-21 09:19:57 -0800
commitd97eae3338f1a4657c35ad136ea426f66d6936f2 (patch)
treef58154dc0966f2c1f9377a7a628ee4e4c537410a /toolsrc/src/vcpkg-test/strings.cpp
parentedb61470d85ab5583c99b998983bab2eeb454929 (diff)
downloadvcpkg-d97eae3338f1a4657c35ad136ea426f66d6936f2.tar.gz
vcpkg-d97eae3338f1a4657c35ad136ea426f66d6936f2.zip
Print failing upload attempts in !debug. (#15206)
Other changes: * Changed Strings::replace_all to use more StringView * Introduced Strings::inplace_replace_all for the common x = replace_all(move(x) pattern and tests -> Also fixed bug if the search string was empty consuming infinite memory! * Added many missing {}s in binarycaching.cpp
Diffstat (limited to 'toolsrc/src/vcpkg-test/strings.cpp')
-rw-r--r--toolsrc/src/vcpkg-test/strings.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg-test/strings.cpp b/toolsrc/src/vcpkg-test/strings.cpp
index ecf0524bc..32fe5b3af 100644
--- a/toolsrc/src/vcpkg-test/strings.cpp
+++ b/toolsrc/src/vcpkg-test/strings.cpp
@@ -71,3 +71,44 @@ TEST_CASE ("edit distance", "[strings]")
REQUIRE(byte_edit_distance("", "hello") == 5);
REQUIRE(byte_edit_distance("world", "") == 5);
}
+
+TEST_CASE ("replace_all", "[strings]")
+{
+ REQUIRE(vcpkg::Strings::replace_all("literal", "ter", "x") == "lixal");
+}
+
+TEST_CASE ("inplace_replace_all", "[strings]")
+{
+ using vcpkg::Strings::inplace_replace_all;
+ std::string target;
+ inplace_replace_all(target, "", "content");
+ REQUIRE(target.empty());
+ target = "aa";
+ inplace_replace_all(target, "a", "content");
+ REQUIRE(target == "contentcontent");
+ inplace_replace_all(target, "content", "");
+ REQUIRE(target.empty());
+ target = "ababababa";
+ inplace_replace_all(target, "aba", "X");
+ REQUIRE(target == "XbXba");
+ target = "ababababa";
+ inplace_replace_all(target, "aba", "aba");
+ REQUIRE(target == "ababababa");
+}
+
+TEST_CASE ("inplace_replace_all(char)", "[strings]")
+{
+ using vcpkg::Strings::inplace_replace_all;
+ static_assert(noexcept(inplace_replace_all(std::declval<std::string&>(), 'a', 'a')));
+
+ std::string target;
+ inplace_replace_all(target, ' ', '?');
+ REQUIRE(target.empty());
+ target = "hello";
+ inplace_replace_all(target, 'l', 'w');
+ REQUIRE(target == "hewwo");
+ inplace_replace_all(target, 'w', 'w');
+ REQUIRE(target == "hewwo");
+ inplace_replace_all(target, 'x', '?');
+ REQUIRE(target == "hewwo");
+}