|
24 | 24 | TEST_CASE("TableBBCode") |
25 | 25 | { |
26 | 26 | // some rather standard table BB code |
27 | | - TableBBCode table("table"); |
| 27 | + const TableBBCode table("table"); |
28 | 28 |
|
29 | 29 | SECTION("empty string stays unchanged") |
30 | 30 | { |
@@ -119,6 +119,84 @@ TEST_CASE("TableBBCode") |
119 | 119 | } |
120 | 120 | } |
121 | 121 |
|
| 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 | + |
122 | 200 | SECTION("alignment parameter tests") |
123 | 201 | { |
124 | 202 | SECTION("table with align left") |
|
0 commit comments