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

LeonetienneLanguage-adjustments nyow onwy affect compwete worwds. Nyice and tested <3333 ^.^b172ec9

master
5.9 KiB203 linesraw
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
8    const std::string in = "";
9    const std::string expected = "";
10
11    // Exercise
12    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "findme", "putme");
13
14    // Verify
15    REQUIRE(result == expected);
16}
17
18// Tests that simple replacing works
19TEST_CASE(__FILE__"/SimpleReplacing", "[]")
20{
21    // Setup
22    const std::string in = "Hello $user, you must be $user, so i am calling you $user.";
23    const std::string expected = "Hello bob, you must be bob, so i am calling you bob.";
24
25    // Exercise
26    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "$user", "bob");
27
28    // Verify
29    REQUIRE(result == expected);
30}
31
32// Find-string is empty
33TEST_CASE(__FILE__"/FindEmpty", "[]")
34{
35    // Setup
36    const std::string in = "Hello $user, you must be $user, so i am calling you $user.";
37    const std::string expected = in;
38
39    // Exercise
40    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "", "bob");
41
42    // Verify
43    REQUIRE(result == expected);
44}
45
46// Sub-string is empty
47TEST_CASE(__FILE__"/SubEmpty", "[]")
48{
49    // Setup
50    const std::string in = "Hello $user, you must be $user, so i am calling you $user.";
51    const std::string expected = "Hello , you must be , so i am calling you .";
52
53    // Exercise
54    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "$user", "");
55
56    // Verify
57    REQUIRE(result == expected);
58}
59
60// Usual use-case
61TEST_CASE(__FILE__"/KeepSigns", "[]")
62{
63    // Setup
64    const std::string in = "Hello Alice, lowercase alice, WTF ALICE?!";
65    const std::string expected = "Hello Bob, lowercase bob, WTF BOB?!";
66
67    // Exercise
68    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "alice", "bob");
69
70    // Verify
71    REQUIRE(result == expected);
72}
73
74// Sub-string is longer than find-string
75TEST_CASE(__FILE__"/ExtrapolateSigns", "[]")
76{
77    // Setup
78    const std::string in = "Hi Alice. HI Alice. hi Alice. hI Alice. HIalice. hiALICE.";
79    const std::string expected = "Hello Alice. HELLO Alice. hello Alice. hELLO Alice. HElloalice. heLLOALICE.";
80
81    // Exercise
82    const std::string result = Util::ConditionalReplaceButKeepSigns(in, "hi", "hello");
83
84    // Verify
85    REQUIRE(result == expected);
86}
87
88// Tests that not replacing anything (by callback) returns the original string
89TEST_CASE(__FILE__"/RejectingAllReplacementsChangesNothing", "[]")
90{
91    // Setup
92    const 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?";
93    const std::string expected = in;
94
95    // Exercise
96    const std::string result = Util::ConditionalReplaceButKeepSigns(
97            in,
98            "e",
99            "hello",
100            [](auto, auto, auto){ return false; } // Reject all replacements
101    );
102
103    // Verify
104    REQUIRE(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
111    const std::string in = "Hello, banana.";
112    const std::string expected = in;
113
114    // Exercise
115    Util::ConditionalReplaceButKeepSigns(
116            in,
117            "banana",
118            "hello",
119            [](const std::string& original, const std::string& finding, const std::size_t index) -> bool {
120                REQUIRE(index == 7);
121                return 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
130    const std::string in = "Hello, BANAna.";
131    const std::string expected = in;
132
133    // Exercise
134    Util::ConditionalReplaceButKeepSigns(
135            in,
136            "banana",
137            "hello",
138            [](const std::string& original, const std::string& finding, const std::size_t index) -> bool {
139                REQUIRE(finding == "BANAna");
140                return 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
149    const std::string in = "ding ding Ding Ding Ding Ding DING DING";
150    const 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
156    const std::string result = Util::ConditionalReplaceButKeepSigns(
157            in,
158            "ding",
159            "dong",
160            [ptrCounter](const std::string& original, const std::string& finding, const std::size_t index) -> bool {
161                return (++*ptrCounter) % 2;
162            }
163    );
164
165    // Verify
166    REQUIRE(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
173    const std::string in = "Hello. I like you.";
174    const std::string expected = "Hello! I like you!";
175
176    // Exercise
177    const std::string result = Util::ConditionalReplaceButKeepSigns(
178            in,
179            ".",
180            "!"
181    );
182
183    // Verify
184    REQUIRE(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
191    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.”";
192
193    // Exercise & Verify
194    const std::string result = Util::ConditionalReplaceButKeepSigns(
195            in,
196            "happy",
197            "",
198            [in](const std::string& original, const std::string& finding, const std::size_t index) -> bool {
199                REQUIRE(original == in);
200                return true;
201            }
202    );
203}