Skip to content

Commit 6a6a643

Browse files
committed
tests: add tests for width limit of TableBBCode
This is currently not used in pmdb, but it is used in htmlify which uses pmdb as submodule.
1 parent b0b69bd commit 6a6a643

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

tests/components/bbcode/TableBBCode.cpp

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
TEST_CASE("TableBBCode")
2525
{
2626
// some rather standard table BB code
27-
TableBBCode table("table");
27+
const TableBBCode table("table");
2828

2929
SECTION("empty string stays unchanged")
3030
{
@@ -119,6 +119,84 @@ TEST_CASE("TableBBCode")
119119
}
120120
}
121121

122+
SECTION("width limit tests")
123+
{
124+
const TableBBCode limited_table("table", TableClasses(), 75);
125+
126+
SECTION("table with width in pixels below limit")
127+
{
128+
std::string text = "[table=\"width: 72\"][tr][td]Content goes here.[/td][/tr][/table]";
129+
limited_table.applyToText(text);
130+
REQUIRE( text == "<table width=\"72\"><tr><td>Content goes here.</td></tr></table>" );
131+
}
132+
133+
SECTION("table with width in pixels exactly at the limit")
134+
{
135+
std::string text = "[table=\"width: 75\"][tr][td]Content goes here.[/td][/tr][/table]";
136+
limited_table.applyToText(text);
137+
REQUIRE( text == "<table width=\"75\"><tr><td>Content goes here.</td></tr></table>" );
138+
}
139+
140+
SECTION("table with width in pixels above limit")
141+
{
142+
std::string text = "[table=\"width: 80\"][tr][td]Content goes here.[/td][/tr][/table]";
143+
limited_table.applyToText(text);
144+
REQUIRE( text == "<table><tr><td>Content goes here.</td></tr></table>" );
145+
}
146+
147+
SECTION("table with width in percent 'below' limit")
148+
{
149+
std::string text = "[table=\"width: 25%\"][tr][td]Content goes here.[/td][/tr][/table]";
150+
limited_table.applyToText(text);
151+
REQUIRE( text == "<table width=\"25%\"><tr><td>Content goes here.</td></tr></table>" );
152+
}
153+
154+
SECTION("table with width in percent 'above' limit")
155+
{
156+
std::string text = "[table=\"width: 85%\"][tr][td]Content goes here.[/td][/tr][/table]";
157+
limited_table.applyToText(text);
158+
// Percentage values are not subjected to the limit, so they always pass.
159+
REQUIRE( text == "<table width=\"85%\"><tr><td>Content goes here.</td></tr></table>" );
160+
}
161+
162+
SECTION("cell with width in pixels below limit")
163+
{
164+
std::string text = "[table][tr][td=\"width: 55\"]Content goes here.[/td][/tr][/table]";
165+
limited_table.applyToText(text);
166+
REQUIRE( text == "<table><tr><td width=\"55\">Content goes here.</td></tr></table>" );
167+
}
168+
169+
SECTION("cell with width in pixels exactly at the limit")
170+
{
171+
std::string text = "[table][tr][td=\"width: 75\"]Content goes here.[/td][/tr][/table]";
172+
limited_table.applyToText(text);
173+
REQUIRE( text == "<table><tr><td width=\"75\">Content goes here.</td></tr></table>" );
174+
}
175+
176+
SECTION("cell with width in pixels above limit")
177+
{
178+
std::string text = "[table][tr][td=\"width: 76\"]Content goes here.[/td][/tr][/table]";
179+
limited_table.applyToText(text);
180+
// Limit is currently not applied to cell width.
181+
REQUIRE( text == "<table><tr><td width=\"76\">Content goes here.</td></tr></table>" );
182+
}
183+
184+
SECTION("cell with width in percent 'below' limit")
185+
{
186+
std::string text = "[table][tr][td=\"width: 42%\"]Content goes here.[/td][/tr][/table]";
187+
limited_table.applyToText(text);
188+
CHECK( text == "<table><tr><td width=\"42%\">Content goes here.</td></tr></table>" );
189+
}
190+
191+
SECTION("cell with width in percent 'above' limit")
192+
{
193+
std::string text = "[table][tr][td=\"width: 95%\"]Content goes here.[/td][/tr][/table]";
194+
limited_table.applyToText(text);
195+
// Percentage values are not subjected to the limit, so they always pass.
196+
CHECK( text == "<table><tr><td width=\"95%\">Content goes here.</td></tr></table>" );
197+
}
198+
}
199+
122200
SECTION("alignment parameter tests")
123201
{
124202
SECTION("table with align left")

0 commit comments

Comments
 (0)