Skip to content

Commit 09f3806

Browse files
committed
tests: add tests for nested quotes + names in single quotes in quote tag
1 parent bcc2203 commit 09f3806

File tree

1 file changed

+268
-0
lines changed

1 file changed

+268
-0
lines changed

tests/components/bbcode/quotes.cpp

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ TEST_CASE("Quotes")
119119
REQUIRE( with_quotes == expected );
120120
}
121121

122+
SECTION("quote with name in single quotes")
123+
{
124+
const std::string text = "Blah, blah.\n[quote='[W]orld']Hello![/quote]\nMore blah.";
125+
const auto with_quotes = handleQuotes(text, forum_url);
126+
const std::string expected = std::string("Blah, blah.\n")
127+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
128+
+ " <tr><td>\n"
129+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
130+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
131+
+ " <tr>\n"
132+
+ " <td style=\"border:1px inset\">\n"
133+
+ " <div>\n"
134+
+ " Zitat von <strong>[W]orld</strong>\n"
135+
+ " </div>\n"
136+
+ " <div style=\"font-style:italic\">"
137+
+ "Hello!"
138+
+ "</div>\n"
139+
+ " </td>\n"
140+
+ " </tr>\n"
141+
+ " </table>\n"
142+
+ "</td></tr>\n"
143+
+ "</table>"
144+
+ "\nMore blah.";
145+
REQUIRE( with_quotes == expected );
146+
}
147+
122148
SECTION("quote with name and post number")
123149
{
124150
const std::string text = "Blah, blah.\n[quote=World;123654789]Hello![/quote]\nMore blah.";
@@ -142,5 +168,247 @@ TEST_CASE("Quotes")
142168
+ "\nMore blah.";
143169
REQUIRE( with_quotes == expected );
144170
}
171+
172+
SECTION("quote with name in and post number in single quotes")
173+
{
174+
const std::string text = "Blah, blah.\n[quote='[W]orld;21973207']Hello![/quote]\nMore blah.";
175+
const auto with_quotes = handleQuotes(text, forum_url);
176+
const std::string expected = std::string("Blah, blah.\n")
177+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
178+
+ " <tr><td>\n"
179+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
180+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
181+
+ " <tr>\n"
182+
+ " <td class=\"alt2\" style=\"border:1px inset\">\n"
183+
+ " <div>\n"
184+
+ " Zitat von <strong>[W]orld</strong>\n"
185+
+ " <a href=\"https://for.um/showthread.php?p=21973207#post21973207"
186+
+ "\" rel=\"nofollow\"><img class=\"inlineimg\" src=\"img/buttons/viewpost.gif\" border=\"0\" alt=\"Beitrag anzeigen\"></a>\n"
187+
+ " </div>\n"
188+
+ " <div style=\"font-style:italic\">"
189+
+ "Hello!"
190+
+ "</div>\n </td>\n </tr>\n"
191+
+ " </table>\n </td></tr>\n</table>"
192+
+ "\nMore blah.";
193+
REQUIRE( with_quotes == expected );
194+
}
195+
196+
SECTION("nested quote: simple")
197+
{
198+
const std::string text = "Blah, blah.\n[quote]This is a quote.\n[quote]Another quote.[/quote][/quote]\nMore blah.";
199+
const auto with_quotes = handleQuotes(text, forum_url);
200+
const std::string expected = std::string("Blah, blah.\n")
201+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
202+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
203+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
204+
+ " <tr>\n"
205+
+ " <td style=\"border:1px inset\">"
206+
+ "This is a quote.\n"
207+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
208+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
209+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
210+
+ " <tr>\n"
211+
+ " <td style=\"border:1px inset\">"
212+
+ "Another quote."
213+
+ "</td>\n"
214+
+ " </tr>\n"
215+
+ " </table>\n"
216+
+ "</td></tr>\n"
217+
+ "</table>"
218+
+ "</td>\n"
219+
+ " </tr>\n"
220+
+ " </table>\n"
221+
+ "</td></tr>\n"
222+
+ "</table>"
223+
+ "\nMore blah.";
224+
REQUIRE( with_quotes == expected );
225+
}
226+
227+
SECTION("nested quote: simple outer quote, inner quote with name")
228+
{
229+
const std::string text = "Blah, blah.\n[quote]This is a quote.\n[quote=Author]Another quote.[/quote][/quote]\nMore blah.";
230+
const auto with_quotes = handleQuotes(text, forum_url);
231+
const std::string expected = std::string("Blah, blah.\n")
232+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
233+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
234+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
235+
+ " <tr>\n"
236+
+ " <td style=\"border:1px inset\">"
237+
+ "This is a quote.\n"
238+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
239+
+ " <tr><td>\n"
240+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
241+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
242+
+ " <tr>\n"
243+
+ " <td style=\"border:1px inset\">\n"
244+
+ " <div>\n"
245+
+ " Zitat von <strong>Author</strong>\n"
246+
+ " </div>\n"
247+
+ " <div style=\"font-style:italic\">"
248+
+ "Another quote."
249+
+ "</div>\n"
250+
+ " </td>\n"
251+
+ " </tr>\n"
252+
+ " </table>\n"
253+
+ "</td></tr>\n"
254+
+ "</table>"
255+
+ "</td>\n"
256+
+ " </tr>\n"
257+
+ " </table>\n"
258+
+ "</td></tr>\n"
259+
+ "</table>"
260+
+ "\nMore blah.";
261+
REQUIRE( with_quotes == expected );
262+
}
263+
264+
SECTION("nested quote: simple outer quote, inner quote with name and post number")
265+
{
266+
const std::string text = "Blah, blah.\n[quote]This is a quote.\n[quote=Author;987654321]Another quote.[/quote][/quote]\nMore blah.";
267+
const auto with_quotes = handleQuotes(text, forum_url);
268+
const std::string expected = std::string("Blah, blah.\n")
269+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
270+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
271+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
272+
+ " <tr>\n"
273+
+ " <td style=\"border:1px inset\">"
274+
+ "This is a quote.\n"
275+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
276+
+ " <tr><td>\n"
277+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
278+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
279+
+ " <tr>\n"
280+
+ " <td class=\"alt2\" style=\"border:1px inset\">\n"
281+
+ " <div>\n"
282+
+ " Zitat von <strong>Author</strong>\n"
283+
+ " <a href=\"https://for.um/showthread.php?p=987654321#post987654321"
284+
+ "\" rel=\"nofollow\"><img class=\"inlineimg\" src=\"img/buttons/viewpost.gif\" border=\"0\" alt=\"Beitrag anzeigen\"></a>\n"
285+
+ " </div>\n"
286+
+ " <div style=\"font-style:italic\">"
287+
+ "Another quote."
288+
+ "</div>\n </td>\n </tr>\n"
289+
+ " </table>\n </td></tr>\n</table>"
290+
+ "</td>\n"
291+
+ " </tr>\n"
292+
+ " </table>\n"
293+
+ "</td></tr>\n"
294+
+ "</table>"
295+
+ "\nMore blah.";
296+
REQUIRE( with_quotes == expected );
297+
}
298+
299+
SECTION("nested quote: outer quote with name, simple inner quote")
300+
{
301+
const std::string text = "Blah, blah.\n[quote=Alice]This is a quote.\n[quote]Another quote.[/quote][/quote]\nMore blah.";
302+
const auto with_quotes = handleQuotes(text, forum_url);
303+
const std::string expected = std::string("Blah, blah.\n")
304+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
305+
+ " <tr><td>\n"
306+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
307+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
308+
+ " <tr>\n"
309+
+ " <td style=\"border:1px inset\">\n"
310+
+ " <div>\n"
311+
+ " Zitat von <strong>Alice</strong>\n"
312+
+ " </div>\n"
313+
+ " <div style=\"font-style:italic\">"
314+
+ "This is a quote.\n"
315+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
316+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
317+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
318+
+ " <tr>\n"
319+
+ " <td style=\"border:1px inset\">"
320+
+ "Another quote."
321+
+ "</td>\n"
322+
+ " </tr>\n"
323+
+ " </table>\n"
324+
+ "</td></tr>\n"
325+
+ "</table>"
326+
+ "</div>\n"
327+
+ " </td>\n"
328+
+ " </tr>\n"
329+
+ " </table>\n"
330+
+ "</td></tr>\n"
331+
+ "</table>"
332+
+ "\nMore blah.";
333+
REQUIRE( with_quotes == expected );
334+
}
335+
336+
SECTION("nested quote: outer quote with name and post number, simple inner quote")
337+
{
338+
const std::string text = "Blah, blah.\n[quote=Alice;42]This is a quote.\n[quote]Another quote.[/quote][/quote]\nMore blah.";
339+
const auto with_quotes = handleQuotes(text, forum_url);
340+
const std::string expected = std::string("Blah, blah.\n")
341+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
342+
+ " <tr><td>\n"
343+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
344+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
345+
+ " <tr>\n"
346+
+ " <td class=\"alt2\" style=\"border:1px inset\">\n"
347+
+ " <div>\n"
348+
+ " Zitat von <strong>Alice</strong>\n"
349+
+ " <a href=\"https://for.um/showthread.php?p=42#post42"
350+
+ "\" rel=\"nofollow\"><img class=\"inlineimg\" src=\"img/buttons/viewpost.gif\" border=\"0\" alt=\"Beitrag anzeigen\"></a>\n"
351+
+ " </div>\n"
352+
+ " <div style=\"font-style:italic\">"
353+
+ "This is a quote.\n"
354+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
355+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
356+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
357+
+ " <tr>\n"
358+
+ " <td style=\"border:1px inset\">"
359+
+ "Another quote."
360+
+ "</td>\n"
361+
+ " </tr>\n"
362+
+ " </table>\n"
363+
+ "</td></tr>\n"
364+
+ "</table>"
365+
+ "</div>\n </td>\n </tr>\n"
366+
+ " </table>\n </td></tr>\n</table>"
367+
+ "\nMore blah.";
368+
REQUIRE( with_quotes == expected );
369+
}
370+
371+
SECTION("nested quote: outer and inner quote with name")
372+
{
373+
const std::string text = "Yo dawg.\n[quote=Dawg]I heard you like quotes.\n[quote=Us]So we put a quote in your quote.[/quote][/quote]\nSo you can quote while you quote.";
374+
const auto with_quotes = handleQuotes(text, forum_url);
375+
const std::string expected = std::string("Yo dawg.\n")
376+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
377+
+ " <tr><td>\n"
378+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
379+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
380+
+ " <tr>\n"
381+
+ " <td style=\"border:1px inset\">\n"
382+
+ " <div>\n"
383+
+ " Zitat von <strong>Dawg</strong>\n"
384+
+ " </div>\n"
385+
+ " <div style=\"font-style:italic\">"
386+
+ "I heard you like quotes.\n"
387+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
388+
+ " <tr><td>\n"
389+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
390+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
391+
+ " <tr>\n"
392+
+ " <td style=\"border:1px inset\">\n"
393+
+ " <div>\n"
394+
+ " Zitat von <strong>Us</strong>\n"
395+
+ " </div>\n"
396+
+ " <div style=\"font-style:italic\">"
397+
+ "So we put a quote in your quote."
398+
+ "</div>\n"
399+
+ " </td>\n"
400+
+ " </tr>\n"
401+
+ " </table>\n"
402+
+ "</td></tr>\n"
403+
+ "</table>"
404+
+ "</div>\n"
405+
+ " </td>\n"
406+
+ " </tr>\n"
407+
+ " </table>\n"
408+
+ "</td></tr>\n"
409+
+ "</table>"
410+
+ "\nSo you can quote while you quote.";
411+
REQUIRE( with_quotes == expected );
412+
}
145413
}
146414
}

0 commit comments

Comments
 (0)