From d97eae3338f1a4657c35ad136ea426f66d6936f2 Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Mon, 21 Dec 2020 09:19:57 -0800 Subject: 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 --- toolsrc/src/vcpkg-test/strings.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'toolsrc/src/vcpkg-test') 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(), '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"); +} -- cgit v1.2.3