|
| 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 "../../locate_catch.hpp" |
| 22 | +#include "../../../code/bbcode/DefaultCodes.hpp" |
| 23 | + |
| 24 | +TEST_CASE("default BB codes") |
| 25 | +{ |
| 26 | + const std::string forum_url = "https://for.um/"; |
| 27 | + |
| 28 | + // Currently, the BBCodeParser has no way to directly get the added codes. |
| 29 | + // So we just check whether they are actually applied to texts instead. |
| 30 | + |
| 31 | + SECTION("check that [b], [i], [s] and [u] codes get applied") |
| 32 | + { |
| 33 | + BBCodeParser parser; |
| 34 | + bbcode_default::addDefaultCodes(parser); |
| 35 | + |
| 36 | + const std::string input = "[b]bold[/b] [i]italics[/i] [s]strike throug[/s] [u]underlined[/u]"; |
| 37 | + const std::string expected = "<b>bold</b> <i>italics</i> <span style=\"text-decoration:line-through;\">strike throug</span> <u>underlined</u>"; |
| 38 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 39 | + |
| 40 | + REQUIRE( parsed == expected ); |
| 41 | + } |
| 42 | + |
| 43 | + SECTION("check that [sub] code gets applied") |
| 44 | + { |
| 45 | + BBCodeParser parser; |
| 46 | + bbcode_default::addDefaultCodes(parser); |
| 47 | + |
| 48 | + const std::string input = "a[sub]1[/sub]+a[sub]2[/sub]=a[sub]3[/sub]"; |
| 49 | + const std::string expected = "a<sub>1</sub>+a<sub>2</sub>=a<sub>3</sub>"; |
| 50 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 51 | + |
| 52 | + REQUIRE( parsed == expected ); |
| 53 | + } |
| 54 | + |
| 55 | + SECTION("check that [sup] code gets applied") |
| 56 | + { |
| 57 | + BBCodeParser parser; |
| 58 | + bbcode_default::addDefaultCodes(parser); |
| 59 | + |
| 60 | + const std::string input = "a[sup]2[/sup]+b[sup]2[/sup]=c[sup]2[/sup]"; |
| 61 | + const std::string expected = "a<sup>2</sup>+b<sup>2</sup>=c<sup>2</sup>"; |
| 62 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 63 | + |
| 64 | + REQUIRE( parsed == expected ); |
| 65 | + } |
| 66 | + |
| 67 | + SECTION("check that alignment codes get applied") |
| 68 | + { |
| 69 | + BBCodeParser parser; |
| 70 | + bbcode_default::addDefaultCodes(parser); |
| 71 | + |
| 72 | + const std::string input = "[left]left text[/left]\n[right]right text[/right]\n[center]centered text[/center]"; |
| 73 | + const std::string expected = "<div align=\"left\">left text</div><br>\n<div align=\"right\">right text</div><br>\n<center>centered text</center>"; |
| 74 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 75 | + |
| 76 | + REQUIRE( parsed == expected ); |
| 77 | + } |
| 78 | + |
| 79 | + SECTION("check that [tt] code gets applied") |
| 80 | + { |
| 81 | + BBCodeParser parser; |
| 82 | + bbcode_default::addDefaultCodes(parser); |
| 83 | + |
| 84 | + const std::string input = "[tt]code[/tt]"; |
| 85 | + const std::string expected = "<tt style=\"font-size: medium\">code</tt>"; |
| 86 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 87 | + |
| 88 | + REQUIRE( parsed == expected ); |
| 89 | + } |
| 90 | + |
| 91 | + SECTION("check that simple [url] code gets applied") |
| 92 | + { |
| 93 | + BBCodeParser parser; |
| 94 | + bbcode_default::addDefaultCodes(parser); |
| 95 | + |
| 96 | + const std::string input = "[url]https://example.com/?foo=bar&baz=1[/url]"; |
| 97 | + const std::string expected = "<a href=\"https://example.com/?foo=bar&baz=1\" target=\"_blank\">https://example.com/?foo=bar&baz=1</a>"; |
| 98 | + const auto parsed = parser.parse(input, forum_url, HTMLStandard::HTML4_01, true); |
| 99 | + |
| 100 | + REQUIRE( parsed == expected ); |
| 101 | + } |
| 102 | + |
| 103 | + // TODO: Add more checks for the other default codes. |
| 104 | +} |
0 commit comments