Skip to content

Commit bcc2203

Browse files
committed
tests: add initial tests for quote tag replacements
1 parent f8b6c04 commit bcc2203

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

tests/components/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(component_tests_sources
2525
../../code/bbcode/TableBBCode.cpp
2626
../../code/bbcode/TableClasses.cpp
2727
../../code/bbcode/TextProcessor.hpp
28+
../../code/bbcode/quotes.cpp
2829
../../code/filters/FilterUser.cpp
2930
../../code/paths.cpp
3031
../../code/templates/defaults.hpp
@@ -54,6 +55,7 @@ set(component_tests_sources
5455
bbcode/Smilie.cpp
5556
bbcode/TableBBCode.cpp
5657
bbcode/TablePreProcessor.cpp
58+
bbcode/quotes.cpp
5759
filter/FilterUser.cpp
5860
names_to_controlsequences.cpp
5961
paths.cpp

tests/components/bbcode/quotes.cpp

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
-------------------------------------------------------------------------------
3+
This file is part of the Private Message Database test suite.
4+
Copyright (C) 2025 Dirk Stolle
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
-------------------------------------------------------------------------------
19+
*/
20+
21+
#include <vector>
22+
#include "../../locate_catch.hpp"
23+
#include "../../../code/bbcode/quotes.hpp"
24+
25+
TEST_CASE("Quotes")
26+
{
27+
SECTION("getClosingQuoteTagPosition")
28+
{
29+
SECTION("empty string")
30+
{
31+
const std::string text = "";
32+
const auto pos = getClosingQuoteTagPosition(text, 0);
33+
REQUIRE( pos == std::string::npos );
34+
}
35+
36+
SECTION("string without quote tag")
37+
{
38+
const std::string text = "This is a text without quotes.";
39+
const auto pos = getClosingQuoteTagPosition(text, 0);
40+
REQUIRE( pos == std::string::npos );
41+
}
42+
43+
SECTION("string quote tag (lower case)")
44+
{
45+
const std::string text = "Blah, blah.\n[quote]This is a quote.[/quote]\nMore blah.";
46+
const auto pos = getClosingQuoteTagPosition(text, 0);
47+
REQUIRE( pos == 35 );
48+
}
49+
50+
SECTION("string quote tag (upper case)")
51+
{
52+
const std::string text = "Blah, blah.\n[QUOTE]This is a quote.[/QUOTE]\nMore blah.";
53+
const auto pos = getClosingQuoteTagPosition(text, 0);
54+
REQUIRE( pos == 35 );
55+
}
56+
}
57+
58+
SECTION("handleQuotes")
59+
{
60+
const std::string forum_url = "https://for.um/";
61+
62+
SECTION("empty text")
63+
{
64+
const std::string text = "";
65+
const auto with_quotes = handleQuotes(text, forum_url);
66+
REQUIRE( text == with_quotes );
67+
}
68+
69+
SECTION("text without quotes")
70+
{
71+
const std::string text = "Blah, blah.\nThere is no quote.\nMore blah.";
72+
const auto with_quotes = handleQuotes(text, forum_url);
73+
REQUIRE( text == with_quotes );
74+
}
75+
76+
SECTION("simple quote")
77+
{
78+
const std::string text = "Blah, blah.\n[quote]This is a quote.[/quote]\nMore blah.";
79+
const auto with_quotes = handleQuotes(text, forum_url);
80+
const std::string expected = std::string("Blah, blah.\n")
81+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
82+
+ "<tr><td><div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
83+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
84+
+ " <tr>\n"
85+
+ " <td style=\"border:1px inset\">"
86+
+ "This is a quote."
87+
+ "</td>\n"
88+
+ " </tr>\n"
89+
+ " </table>\n"
90+
+ "</td></tr>\n"
91+
+ "</table>"
92+
+ "\nMore blah.";
93+
REQUIRE( with_quotes == expected );
94+
}
95+
96+
SECTION("quote with name")
97+
{
98+
const std::string text = "Blah, blah.\n[quote=World]Hello![/quote]\nMore blah.";
99+
const auto with_quotes = handleQuotes(text, forum_url);
100+
const std::string expected = std::string("Blah, blah.\n")
101+
+ "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"20\">\n"
102+
+ " <tr><td>\n"
103+
+ " <div class=\"smallfont\" style=\"margin-bottom:2px\">Zitat:</div>\n"
104+
+ " <table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"
105+
+ " <tr>\n"
106+
+ " <td style=\"border:1px inset\">\n"
107+
+ " <div>\n"
108+
+ " Zitat von <strong>World</strong>\n"
109+
+ " </div>\n"
110+
+ " <div style=\"font-style:italic\">"
111+
+ "Hello!"
112+
+ "</div>\n"
113+
+ " </td>\n"
114+
+ " </tr>\n"
115+
+ " </table>\n"
116+
+ "</td></tr>\n"
117+
+ "</table>"
118+
+ "\nMore blah.";
119+
REQUIRE( with_quotes == expected );
120+
}
121+
122+
SECTION("quote with name and post number")
123+
{
124+
const std::string text = "Blah, blah.\n[quote=World;123654789]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 class=\"alt2\" style=\"border:1px inset\">\n"
133+
+ " <div>\n"
134+
+ " Zitat von <strong>World</strong>\n"
135+
+ " <a href=\"https://for.um/showthread.php?p=123654789#post123654789"
136+
+ "\" rel=\"nofollow\"><img class=\"inlineimg\" src=\"img/buttons/viewpost.gif\" border=\"0\" alt=\"Beitrag anzeigen\"></a>\n"
137+
+ " </div>\n"
138+
+ " <div style=\"font-style:italic\">"
139+
+ "Hello!"
140+
+ "</div>\n </td>\n </tr>\n"
141+
+ " </table>\n </td></tr>\n</table>"
142+
+ "\nMore blah.";
143+
REQUIRE( with_quotes == expected );
144+
}
145+
}
146+
}

tests/components/component_tests.cbp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
<Unit filename="../../code/bbcode/TableClasses.cpp" />
7878
<Unit filename="../../code/bbcode/TableClasses.hpp" />
7979
<Unit filename="../../code/bbcode/TextProcessor.hpp" />
80+
<Unit filename="../../code/bbcode/quotes.cpp" />
81+
<Unit filename="../../code/bbcode/quotes.hpp" />
8082
<Unit filename="../../code/filters/Filter.hpp" />
8183
<Unit filename="../../code/filters/FilterUser.cpp" />
8284
<Unit filename="../../code/filters/FilterUser.hpp" />
@@ -118,6 +120,7 @@
118120
<Unit filename="bbcode/Smilie.cpp" />
119121
<Unit filename="bbcode/TableBBCode.cpp" />
120122
<Unit filename="bbcode/TablePreProcessor.cpp" />
123+
<Unit filename="bbcode/quotes.cpp" />
121124
<Unit filename="filter/FilterUser.cpp" />
122125
<Unit filename="main.cpp" />
123126
<Unit filename="names_to_controlsequences.cpp" />

0 commit comments

Comments
 (0)