From b172ec9ee901d95bdd959665399a87ff033ed9a9 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sun, 13 Feb 2022 14:28:04 +0100 Subject: Language-adjustments nyow onwy affect compwete worwds. Nyice and tested <3333 ^.^ --- Test/ConditionalReplaceButKeepSigns.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'Test/ConditionalReplaceButKeepSigns.cpp') diff --git a/Test/ConditionalReplaceButKeepSigns.cpp b/Test/ConditionalReplaceButKeepSigns.cpp index 1994528..99c3bcb 100644 --- a/Test/ConditionalReplaceButKeepSigns.cpp +++ b/Test/ConditionalReplaceButKeepSigns.cpp @@ -97,7 +97,7 @@ TEST_CASE(__FILE__"/RejectingAllReplacementsChangesNothing", "[]") in, "e", "hello", - [](auto, auto){ return false; } // Reject all replacements + [](auto, auto, auto){ return false; } // Reject all replacements ); // Verify @@ -116,7 +116,7 @@ TEST_CASE(__FILE__"/Callback_Index_Matches", "[]") in, "banana", "hello", - [](const std::string& finding, const std::size_t index) -> bool { + [](const std::string& original, const std::string& finding, const std::size_t index) -> bool { REQUIRE(index == 7); return true; } @@ -135,7 +135,7 @@ TEST_CASE(__FILE__"/Callback_Finding_Matches", "[]") in, "banana", "hello", - [](const std::string& finding, const std::size_t index) -> bool { + [](const std::string& original, const std::string& finding, const std::size_t index) -> bool { REQUIRE(finding == "BANAna"); return true; } @@ -157,7 +157,7 @@ TEST_CASE(__FILE__"/Callback_Conditional_Rejecting_Works", "[]") in, "ding", "dong", - [ptrCounter](const std::string& finding, const std::size_t index) -> bool { + [ptrCounter](const std::string& original, const std::string& finding, const std::size_t index) -> bool { return (++*ptrCounter) % 2; } ); @@ -183,3 +183,21 @@ TEST_CASE(__FILE__"/ReplaceSymbols", "[]") // Verify REQUIRE(result == expected); } + +// The callback ALWAYS receives the same, identical 'original string' value on each call, without any replacements made to it. +TEST_CASE(__FILE__"/Original-value_on_callback_is_correct", "[]") +{ + // Setup + const std::string in = "I felt happy because I saw the others were happy and because I knew I should feel happy, but I wasn't really happy.”"; + + // Exercise & Verify + const std::string result = Util::ConditionalReplaceButKeepSigns( + in, + "happy", + "", + [in](const std::string& original, const std::string& finding, const std::size_t index) -> bool { + REQUIRE(original == in); + return true; + } + ); +} -- cgit v1.2.3