yum-mirror/UwwwuPP
A rehost of leonetienne's UwwwuPP, a simple text filter to uwu-ify English text.
git clone https://git.yummers.dev/yum-mirror/UwwwuPP
b172ec9
master
1#include <Util.h> 2#include "Catch2.h" 3 4// Test that putting in an empty string returns an empty string 5TEST_CASE (__FILE__ "/EmptyInputString" ,"[]" ) 6{ 7// Setup 8const std::string in = "" ; 9const std::string expected = "" ; 10 11// Exercise 12const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"findme" ,"putme" ); 13 14// Verify 15REQUIRE (result == expected ); 16} 17 18// Tests that simple replacing works 19TEST_CASE (__FILE__ "/SimpleReplacing" ,"[]" ) 20{ 21// Setup 22const std::string in = "Hello $user, you must be $user, so i am calling you $user." ; 23const std::string expected = "Hello bob, you must be bob, so i am calling you bob." ; 24 25// Exercise 26const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"$user" ,"bob" ); 27 28// Verify 29REQUIRE (result == expected ); 30} 31 32// Find-string is empty 33TEST_CASE (__FILE__ "/FindEmpty" ,"[]" ) 34{ 35// Setup 36const std::string in = "Hello $user, you must be $user, so i am calling you $user." ; 37const std::string expected = in ; 38 39// Exercise 40const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"" ,"bob" ); 41 42// Verify 43REQUIRE (result == expected ); 44} 45 46// Sub-string is empty 47TEST_CASE (__FILE__ "/SubEmpty" ,"[]" ) 48{ 49// Setup 50const std::string in = "Hello $user, you must be $user, so i am calling you $user." ; 51const std::string expected = "Hello , you must be , so i am calling you ." ; 52 53// Exercise 54const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"$user" ,"" ); 55 56// Verify 57REQUIRE (result == expected ); 58} 59 60// Usual use-case 61TEST_CASE (__FILE__ "/KeepSigns" ,"[]" ) 62{ 63// Setup 64const std::string in = "Hello Alice, lowercase alice, WTF ALICE?!" ; 65const std::string expected = "Hello Bob, lowercase bob, WTF BOB?!" ; 66 67// Exercise 68const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"alice" ,"bob" ); 69 70// Verify 71REQUIRE (result == expected ); 72} 73 74// Sub-string is longer than find-string 75TEST_CASE (__FILE__ "/ExtrapolateSigns" ,"[]" ) 76{ 77// Setup 78const std::string in = "Hi Alice. HI Alice. hi Alice. hI Alice. HIalice. hiALICE." ; 79const std::string expected = "Hello Alice. HELLO Alice. hello Alice. hELLO Alice. HElloalice. heLLOALICE." ; 80 81// Exercise 82const std::string result = Util ::ConditionalReplaceButKeepSigns (in ,"hi" ,"hello" ); 83 84// Verify 85REQUIRE (result == expected ); 86} 87 88// Tests that not replacing anything (by callback) returns the original string 89TEST_CASE (__FILE__ "/RejectingAllReplacementsChangesNothing" ,"[]" ) 90{ 91// Setup 92const std::string in = "Hello, i am a generic string with a lot of e's. It would be a shame of any of these e's were lost, wouldn't it?" ; 93const std::string expected = in ; 94 95// Exercise 96const std::string result = Util ::ConditionalReplaceButKeepSigns ( 97in , 98"e" , 99"hello" , 100 [](auto ,auto ,auto ){return false; }// Reject all replacements 101 ); 102 103// Verify 104REQUIRE (result == expected ); 105} 106 107// Tests that the callback returns the correct index for a finding 108TEST_CASE (__FILE__ "/Callback_Index_Matches" ,"[]" ) 109{ 110// Setup 111const std::string in = "Hello, banana." ; 112const std::string expected = in ; 113 114// Exercise 115Util ::ConditionalReplaceButKeepSigns ( 116in , 117"banana" , 118"hello" , 119 [](const std::string & original ,const std::string & finding ,const std::size_t index )-> bool { 120REQUIRE (index == 7 ); 121return true; 122 } 123 ); 124} 125 126// Tests that the callback returns the correct substring of a finding 127TEST_CASE (__FILE__ "/Callback_Finding_Matches" ,"[]" ) 128{ 129// Setup 130const std::string in = "Hello, BANAna." ; 131const std::string expected = in ; 132 133// Exercise 134Util ::ConditionalReplaceButKeepSigns ( 135in , 136"banana" , 137"hello" , 138 [](const std::string & original ,const std::string & finding ,const std::size_t index )-> bool { 139REQUIRE (finding == "BANAna" ); 140return true; 141 } 142 ); 143} 144 145// Tests that the callback function works, here we will be rejecting every other finding 146TEST_CASE (__FILE__ "/Callback_Conditional_Rejecting_Works" ,"[]" ) 147{ 148// Setup 149const std::string in = "ding ding Ding Ding Ding Ding DING DING" ; 150const std::string expected = "ding dong Ding Dong Ding Dong DING DONG" ; 151 152 std::size_t counter = 1 ;// Start one cycle off 153 std::size_t * ptrCounter = & counter ; 154 155// Exercise 156const std::string result = Util ::ConditionalReplaceButKeepSigns ( 157in , 158"ding" , 159"dong" , 160 [ptrCounter ](const std::string & original ,const std::string & finding ,const std::size_t index )-> bool { 161return (++* ptrCounter ) %2 ; 162 } 163 ); 164 165// Verify 166REQUIRE (expected == result ); 167} 168 169// Tests that replacing symbols works... Why ever you would use this method for this... 170TEST_CASE (__FILE__ "/ReplaceSymbols" ,"[]" ) 171{ 172// Setup 173const std::string in = "Hello. I like you." ; 174const std::string expected = "Hello! I like you!" ; 175 176// Exercise 177const std::string result = Util ::ConditionalReplaceButKeepSigns ( 178in , 179"." , 180"!" 181 ); 182 183// Verify 184REQUIRE (result == expected ); 185} 186 187// The callback ALWAYS receives the same, identical 'original string' value on each call, without any replacements made to it. 188TEST_CASE (__FILE__ "/Original-value_on_callback_is_correct" ,"[]" ) 189{ 190// Setup 191const 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.”" ; 192 193// Exercise & Verify 194const std::string result = Util ::ConditionalReplaceButKeepSigns ( 195in , 196"happy" , 197"" , 198 [in ](const std::string & original ,const std::string & finding ,const std::size_t index )-> bool { 199REQUIRE (original == in ); 200return true; 201 } 202 ); 203}