chore: Add clang-format

This commit is contained in:
Petra Baranski
2024-11-16 05:50:22 +01:00
committed by GitHub
parent 1f12bc15b6
commit d0dae091e0
48 changed files with 766 additions and 774 deletions

View File

@@ -15,10 +15,10 @@ class MADDY_CHECKLISTPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::ChecklistParser> clParser;
void
SetUp() override
void SetUp() override
{
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
getBlockParserForLineCallback = [](const std::string& line)
{
if (maddy::ChecklistParser::IsStartingLine(line))
{
@@ -32,15 +32,16 @@ protected:
};
this->clParser = std::make_shared<maddy::ChecklistParser>(
nullptr,
getBlockParserForLineCallback
nullptr, getBlockParserForLineCallback
);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
TEST_F(
MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
)
{
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [ ] a"));
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [x] b"));
@@ -53,12 +54,11 @@ TEST_F(MADDY_CHECKLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist)
{
std::vector<std::string> markdown = {
"- [ ] a"
, "- [x] b"
, ""
};
std::string expected = "<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> b</label></li></ul>";
std::vector<std::string> markdown = {"- [ ] a", "- [x] b", ""};
std::string expected =
"<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> "
"b</label></li></ul>";
for (std::string md : markdown)
{
@@ -76,14 +76,15 @@ TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHtmlChecklist)
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
{
std::vector<std::string> markdown = {
"- [ ] a"
, " - [ ] d"
, " - [ ] e"
, "- [ ] b"
, " - [x] c"
, ""
"- [ ] a", " - [ ] d", " - [ ] e", "- [ ] b", " - [x] c", ""
};
std::string expected = "<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> d</label></li><li><label><input type=\"checkbox\"/> e</label></li></ul></label></li><li><label><input type=\"checkbox\"/> b<ul class=\"checklist\"><li><label><input type=\"checkbox\" checked=\"checked\"/> c</label></li></ul></label></li></ul>";
std::string expected =
"<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a<ul "
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"d</label></li><li><label><input type=\"checkbox\"/> "
"e</label></li></ul></label></li><li><label><input type=\"checkbox\"/> "
"b<ul class=\"checklist\"><li><label><input type=\"checkbox\" "
"checked=\"checked\"/> c</label></li></ul></label></li></ul>";
for (std::string md : markdown)
{

View File

@@ -15,13 +15,9 @@ class MADDY_CODEBLOCKPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::CodeBlockParser> cbParser;
void
SetUp() override
void SetUp() override
{
this->cbParser = std::make_shared<maddy::CodeBlockParser>(
nullptr,
nullptr
);
this->cbParser = std::make_shared<maddy::CodeBlockParser>(nullptr, nullptr);
}
};
@@ -40,13 +36,11 @@ TEST_F(MADDY_CODEBLOCKPARSER, IsFinishedReturnsFalseInTheBeginning)
TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
{
std::vector<std::string> markdown = {
"```"
, "some code"
, "some other code"
, "```"
"```", "some code", "some other code", "```"
};
std::string expected = "<pre><code>\nsome code\nsome other code\n</code></pre>";
std::string expected =
"<pre><code>\nsome code\nsome other code\n</code></pre>";
for (std::string md : markdown)
{
@@ -63,13 +57,11 @@ TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
TEST_F(MADDY_CODEBLOCKPARSER, ItShouldUseAnythingBehindFirstBackticksAsClass)
{
std::vector<std::string> markdown = {
"```cpp"
, "some code"
, "some other code"
, "```"
"```cpp", "some code", "some other code", "```"
};
std::string expected = "<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
std::string expected =
"<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
for (std::string md : markdown)
{

View File

@@ -24,7 +24,8 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
TEST(MADDY_EMPHASIZEDPARSER, ItDoesNotParseInsideInlineCode)
{
std::string text = "some text `*bla*` `/**text*/` testing _it_ out";
std::string expected = "some text `*bla*` `/**text*/` testing <em>it</em> out";
std::string expected =
"some text `*bla*` `/**text*/` testing <em>it</em> out";
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
emphasizedParser->Parse(text);

View File

@@ -15,19 +15,17 @@ class MADDY_HEADLINEPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::HeadlineParser> hlParser;
void
SetUp() override
void SetUp() override
{
this->hlParser = std::make_shared<maddy::HeadlineParser>(
nullptr,
nullptr
);
this->hlParser = std::make_shared<maddy::HeadlineParser>(nullptr, nullptr);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_HEADLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithOneToSixHashes)
TEST_F(
MADDY_HEADLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithOneToSixHashes
)
{
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("# a"));
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("## a"));
@@ -45,21 +43,16 @@ TEST_F(MADDY_HEADLINEPARSER, IsFinishedAlwaysReturnsTrue)
TEST_F(MADDY_HEADLINEPARSER, ItReplacesMarkdownWithAnHtmlHeadline)
{
std::vector<std::string> markdown = {
"# a"
, "## a"
, "### a"
, "#### a"
, "##### a"
, "###### a"
"# a", "## a", "### a", "#### a", "##### a", "###### a"
};
std::vector<std::string> expected = {
"<h1>a</h1>"
, "<h2>a</h2>"
, "<h3>a</h3>"
, "<h4>a</h4>"
, "<h5>a</h5>"
, "<h6>a</h6>"
"<h1>a</h1>",
"<h2>a</h2>",
"<h3>a</h3>",
"<h4>a</h4>",
"<h5>a</h5>",
"<h6>a</h6>"
};
for (uint8_t i = 0; i < 6; ++i)

View File

@@ -15,19 +15,18 @@ class MADDY_HORIZONTALLINEPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::HorizontalLineParser> hlParser;
void
SetUp() override
void SetUp() override
{
this->hlParser = std::make_shared<maddy::HorizontalLineParser>(
nullptr,
nullptr
);
this->hlParser =
std::make_shared<maddy::HorizontalLineParser>(nullptr, nullptr);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_HORIZONTALLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes)
TEST_F(
MADDY_HORIZONTALLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes
)
{
ASSERT_TRUE(maddy::HorizontalLineParser::IsStartingLine("---"));
}

View File

@@ -15,13 +15,9 @@ class MADDY_HTMLPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::HtmlParser> pParser;
void
SetUp() override
void SetUp() override
{
this->pParser = std::make_shared<maddy::HtmlParser>(
nullptr,
nullptr
);
this->pParser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
}
};
@@ -35,11 +31,7 @@ TEST_F(MADDY_HTMLPARSER, IsFinishedReturnsFalseInTheBeginning)
TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsFalseWhenFacedWithNoSmallerThan)
{
const std::vector<std::string> markdown = {
"> quote"
, "some text"
, "* list"
, "1. numbered list"
, "|table>"
"> quote", "some text", "* list", "1. numbered list", "|table>"
};
for (size_t i = 0; i < markdown.size(); ++i)
@@ -57,17 +49,18 @@ TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsTrueWhenFacedWithSmallerThan)
TEST_F(MADDY_HTMLPARSER, ItReplacesNoHtml)
{
const std::vector<std::string> markdown {
"some text in a paragraph"
, ""
, "<div> some HTML</div>"
, ""
, "<div>more"
, "HTML"
, "</div>"
, ""
const std::vector<std::string> markdown{
"some text in a paragraph",
"",
"<div> some HTML</div>",
"",
"<div>more",
"HTML",
"</div>",
""
};
const std::string expected = "some text in a paragraph <div> some HTML</div><div>more HTML </div>";
const std::string expected =
"some text in a paragraph <div> some HTML</div><div>more HTML </div>";
for (std::string md : markdown)
{

View File

@@ -13,7 +13,8 @@
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
{
std::string text = "Some text ![Image Title](http://example.com/a.png)";
std::string expected = "Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
std::string expected =
"Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
auto imageParser = std::make_shared<maddy::ImageParser>();
imageParser->Parse(text);
@@ -23,8 +24,12 @@ TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithImages)
{
std::string text = "Some text ![Image Title](http://example.com/a.png) bla ![Image Title](http://example.com/a.png)";
std::string expected = "Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/> bla <img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
std::string text =
"Some text ![Image Title](http://example.com/a.png) bla ![Image "
"Title](http://example.com/a.png)";
std::string expected =
"Some text <img src=\"http://example.com/a.png\" alt=\"Image Title\"/> bla "
"<img src=\"http://example.com/a.png\" alt=\"Image Title\"/>";
auto imageParser = std::make_shared<maddy::ImageParser>();
imageParser->Parse(text);

View File

@@ -13,7 +13,8 @@
TEST(MADDY_INLINECODEPARSER, ItReplacesMarkdownWithCodeHTML)
{
std::string text = "some text `bla` text testing `it` out";
std::string expected = "some text <code>bla</code> text testing <code>it</code> out";
std::string expected =
"some text <code>bla</code> text testing <code>it</code> out";
auto emphasizedParser = std::make_shared<maddy::InlineCodeParser>();
emphasizedParser->Parse(text);

View File

@@ -12,7 +12,6 @@
TEST(MADDY_ITALICPARSER, ItReplacesMarkdownWithItalicHTML)
{
std::string text = "some text *bla* text testing *it* out";
std::string expected = "some text <i>bla</i> text testing <i>it</i> out";
auto italicParser = std::make_shared<maddy::ItalicParser>();

View File

@@ -15,13 +15,10 @@ class MADDY_LATEXBLOCKPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::LatexBlockParser> lbParser;
void
SetUp() override
void SetUp() override
{
this->lbParser = std::make_shared<maddy::LatexBlockParser>(
nullptr,
nullptr
);
this->lbParser =
std::make_shared<maddy::LatexBlockParser>(nullptr, nullptr);
}
};
@@ -60,9 +57,7 @@ TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesOneLineMarkdownWithALatexBlock)
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
{
std::vector<std::string> markdown = {
"$$",
"x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.",
"$$"
"$$", "x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.", "$$"
};
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n$$\n";
@@ -82,9 +77,7 @@ TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesAMultilineBlockMarkdownWithALatexBlock)
{
std::vector<std::string> markdown = {
"$$",
"x = {-b \\pm \\sqrt{b^2-4ac}",
"\\over 2a}.$$"
"$$", "x = {-b \\pm \\sqrt{b^2-4ac}", "\\over 2a}.$$"
};
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac}\n\\over 2a}.$$\n";

View File

@@ -13,7 +13,8 @@
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithALink)
{
std::string text = "Some text [Link Title](http://example.com)";
std::string expected = "Some text <a href=\"http://example.com\">Link Title</a>";
std::string expected =
"Some text <a href=\"http://example.com\">Link Title</a>";
auto linkParser = std::make_shared<maddy::LinkParser>();
linkParser->Parse(text);
@@ -23,8 +24,12 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithALink)
TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
{
std::string text = "Some text [Link Title](http://example.com) bla [Link Title](http://example.com)";
std::string expected = "Some text <a href=\"http://example.com\">Link Title</a> bla <a href=\"http://example.com\">Link Title</a>";
std::string text =
"Some text [Link Title](http://example.com) bla [Link "
"Title](http://example.com)";
std::string expected =
"Some text <a href=\"http://example.com\">Link Title</a> bla <a "
"href=\"http://example.com\">Link Title</a>";
auto linkParser = std::make_shared<maddy::LinkParser>();
linkParser->Parse(text);
@@ -34,7 +39,8 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
// -----------------------------------------------------------------------------
class DISABLED_MADDY_LINKPARSER : public ::testing::Test { };
class DISABLED_MADDY_LINKPARSER : public ::testing::Test
{};
// This test is disabled for now, so make sure, to first run the ImageParser
// before using the LinkParser

View File

@@ -15,10 +15,10 @@ class MADDY_ORDEREDLISTPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::OrderedListParser> olParser;
void
SetUp() override
void SetUp() override
{
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
getBlockParserForLineCallback = [](const std::string& line)
{
if (maddy::OrderedListParser::IsStartingLine(line))
{
@@ -32,15 +32,16 @@ protected:
};
this->olParser = std::make_shared<maddy::OrderedListParser>(
nullptr,
getBlockParserForLineCallback
nullptr, getBlockParserForLineCallback
);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_ORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
TEST_F(
MADDY_ORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
)
{
ASSERT_TRUE(maddy::OrderedListParser::IsStartingLine("1. a"));
}
@@ -52,11 +53,7 @@ TEST_F(MADDY_ORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
{
std::vector<std::string> markdown = {
"1. a"
, "* b"
, ""
};
std::vector<std::string> markdown = {"1. a", "* b", ""};
std::string expected = "<ol><li>a</li><li>b</li></ol>";
for (std::string md : markdown)
@@ -75,14 +72,11 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
{
std::vector<std::string> markdown = {
"1. a"
, " 1. d"
, " * e"
, "* b"
, " 1. c"
, ""
"1. a", " 1. d", " * e", "* b", " 1. c", ""
};
std::string expected = "<ol><li>a<ol><li>d</li><li>e</li></ol></li><li>b<ol><li>c</li></ol></li></ol>";
std::string expected =
"<ol><li>a<ol><li>d</li><li>e</li></ol></li><li>b<ol><li>c</li></ol></li></"
"ol>";
for (std::string md : markdown)
{
@@ -97,14 +91,11 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
ASSERT_EQ(expected, outputString);
}
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList)
TEST_F(
MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList
)
{
std::vector<std::string> markdown = {
"1. a"
, "94. b"
, "103. c"
, ""
};
std::vector<std::string> markdown = {"1. a", "94. b", "103. c", ""};
std::string expected = "<ol><li>a</li><li>b</li><li>c</li></ol>";
for (std::string md : markdown)

View File

@@ -15,14 +15,10 @@ class MADDY_PARAGRAPHPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::ParagraphParser> pParser;
void
SetUp() override
void SetUp() override
{
this->pParser = std::make_shared<maddy::ParagraphParser>(
nullptr,
nullptr,
true
);
this->pParser =
std::make_shared<maddy::ParagraphParser>(nullptr, nullptr, true);
}
};
@@ -40,11 +36,7 @@ TEST_F(MADDY_PARAGRAPHPARSER, IsFinishedReturnsFalseInTheBeginning)
TEST_F(MADDY_PARAGRAPHPARSER, ItReplacesMarkdownWithAnHtmlLine)
{
std::vector<std::string> markdown = {
"Some text"
, "and some other text"
, ""
};
std::vector<std::string> markdown = {"Some text", "and some other text", ""};
std::string expected = "<p>Some text and some other text </p>";
for (std::string md : markdown)

View File

@@ -3,10 +3,11 @@
* LICENSE file.
*/
#include "maddy/test_maddy_parser.h"
#include "gmock/gmock.h"
#include "maddy/parser.h"
#include "maddy/test_maddy_parser.h"
// -----------------------------------------------------------------------------
@@ -53,8 +54,8 @@ TEST(MADDY_PARSER, ItShouldParseWithBitwiseConfig)
TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
{
auto config = std::make_shared<maddy::ParserConfig>();
config->enabledParsers = maddy::types::EMPHASIZED_PARSER |
maddy::types::STRONG_PARSER;
config->enabledParsers =
maddy::types::EMPHASIZED_PARSER | maddy::types::STRONG_PARSER;
auto parser = std::make_shared<maddy::Parser>(config);
@@ -70,7 +71,8 @@ TEST(MADDY_PARSER, ItShouldParseInlineCodeInHeadlines)
const std::string headlineTest = R"(
# Some **test** markdown
)";
const std::string expectedHTML = "<h1>Some <strong>test</strong> markdown</h1>";
const std::string expectedHTML =
"<h1>Some <strong>test</strong> markdown</h1>";
std::stringstream markdown(headlineTest);
auto parser = std::make_shared<maddy::Parser>();

View File

@@ -6,7 +6,8 @@
#include <string>
const std::string testMarkdown = "# This is a test\n\
const std::string testMarkdown =
"# This is a test\n\
\n\
This should result in a praragraph\n\
it's that simple.\n\
@@ -69,6 +70,71 @@ foot a|foot b|foot c\n\
\n\
";
const std::string testHtml = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an <em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><p><a name=\"to top\"></a> </p><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
const std::string testHtml2 = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an _ordered_</li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><a name=\"to top\"></a><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
const std::string testHtml3 = "# This is a test <br/>This should result in a praragraph it's that simple. <br/>* an *unordered* list * with some <strong>hierarchy</strong> 1. and an <em>ordered</em> * list * directly * inside <br/>``` var c = 'blub'; ``` <br/>> A Quote > > With some ~~text~~ blocks inside > > * even a list > * should be > * possible > <br/>And well `inline code` should also work. <br/>## Another Headline <br/>And not to forget [link to progsource](http://progsource.de) should work. And well - let's see how an image would be shown: <br/>![an image](http://progsource.de/img/progsource.png) <br/>--- <br/><a name=\"to top\"></a> <br/>### and more headlines <br/>- [ ] how - [ ] about - [ ] a - [x] nice - [x] check - [ ] list <br/>#### even a table <br/>|table> Left header|middle header|last header - | - | - cell 1|cell <strong>2</strong>|cell 3 cell 4|cell 5|cell 6 - | - | - foot a|foot b|foot c |<table <br/>##### h5 ###### h6 <br/>";
const std::string testHtml =
"<h1>This is a test</h1><p>This should result in a praragraph it's that "
"simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some "
"<strong>hierarchy</strong><ol><li>and an "
"<em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</"
"li></ul></li></ul><pre><code>\nvar c = "
"'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> "
"blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible "
"</li></ul></blockquote><p>And well <code>inline code</code> should also "
"work. </p><h2>Another Headline</h2><p>And not to forget <a "
"href=\"http://progsource.de\">link to progsource</a> should work. And well "
"- let's see how an image would be shown: </p><p><img "
"src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> "
"</p><hr/><p><a name=\"to top\"></a> </p><h3>and more headlines</h3><ul "
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"how</label></li><li><label><input type=\"checkbox\"/> about<ul "
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> "
"nice</label></li></ul></label></li><li><label><input type=\"checkbox\" "
"checked=\"checked\"/> check</label></li><li><label><input "
"type=\"checkbox\"/> list</label></li></ul><h4>even a "
"table</h4><table><thead><tr><th>Left header</th><th>middle "
"header</th><th>last header</th></tr></thead><tbody><tr><td>cell "
"1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell "
"4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot "
"a</td><td>foot b</td><td>foot "
"c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
const std::string testHtml2 =
"<h1>This is a test</h1><p>This should result in a praragraph it's that "
"simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some "
"<strong>hierarchy</strong><ol><li>and an "
"_ordered_</li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></"
"li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote "
"</p><p>With some <s>text</s> blocks inside </p><ul><li>even a list "
"</li><li>should be </li><li>possible </li></ul></blockquote><p>And well "
"<code>inline code</code> should also work. </p><h2>Another "
"Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to "
"progsource</a> should work. And well - let's see how an image would be "
"shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an "
"image\"/> </p><hr/><a name=\"to top\"></a><h3>and more headlines</h3><ul "
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"how</label></li><li><label><input type=\"checkbox\"/> about<ul "
"class=\"checklist\"><li><label><input type=\"checkbox\"/> "
"a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> "
"nice</label></li></ul></label></li><li><label><input type=\"checkbox\" "
"checked=\"checked\"/> check</label></li><li><label><input "
"type=\"checkbox\"/> list</label></li></ul><h4>even a "
"table</h4><table><thead><tr><th>Left header</th><th>middle "
"header</th><th>last header</th></tr></thead><tbody><tr><td>cell "
"1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell "
"4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot "
"a</td><td>foot b</td><td>foot "
"c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
const std::string testHtml3 =
"# This is a test <br/>This should result in a praragraph it's that simple. "
"<br/>* an *unordered* list * with some <strong>hierarchy</strong> 1. "
"and an <em>ordered</em> * list * directly * inside <br/>``` var c "
"= 'blub'; ``` <br/>> A Quote > > With some ~~text~~ blocks inside > > * "
"even a list > * should be > * possible > <br/>And well `inline code` should "
"also work. <br/>## Another Headline <br/>And not to forget [link to "
"progsource](http://progsource.de) should work. And well - let's see how an "
"image would be shown: <br/>![an "
"image](http://progsource.de/img/progsource.png) <br/>--- <br/><a name=\"to "
"top\"></a> <br/>### and more headlines <br/>- [ ] how - [ ] about - [ ] a "
" - [x] nice - [x] check - [ ] list <br/>#### even a table <br/>|table> "
"Left header|middle header|last header - | - | - cell 1|cell "
"<strong>2</strong>|cell 3 cell 4|cell 5|cell 6 - | - | - foot a|foot b|foot "
"c |<table <br/>##### h5 ###### h6 <br/>";

View File

@@ -15,19 +15,17 @@ class MADDY_QUOTEPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::QuoteParser> quoteParser;
void
SetUp() override
void SetUp() override
{
this->quoteParser = std::make_shared<maddy::QuoteParser>(
nullptr,
nullptr
);
this->quoteParser = std::make_shared<maddy::QuoteParser>(nullptr, nullptr);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_QUOTEPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfAQuote)
TEST_F(
MADDY_QUOTEPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfAQuote
)
{
ASSERT_TRUE(maddy::QuoteParser::IsStartingLine("> a"));
}
@@ -39,13 +37,7 @@ TEST_F(MADDY_QUOTEPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
TEST_F(MADDY_QUOTEPARSER, ItReplacesMarkdownWithAnHtmlBlockQuote)
{
std::vector<std::string> markdown = {
"> a"
, "> b"
, ">"
, "> c"
, ""
};
std::vector<std::string> markdown = {"> a", "> b", ">", "> c", ""};
std::string expected = "<blockquote>a b c </blockquote>";
for (std::string md : markdown)

View File

@@ -23,8 +23,10 @@ TEST(MADDY_STRIKETHROUGHPARSER, ItReplacesMarkdownWithStrikeThroughHTML)
TEST(MADDY_STRIKETHROUGHPARSER, ItDoesNotParseInsideInlineCode)
{
std::string text = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
std::string expected = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
std::string text =
"some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
std::string expected =
"some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
auto strikeThroughParser = std::make_shared<maddy::StrikeThroughParser>();
strikeThroughParser->Parse(text);

View File

@@ -18,16 +18,11 @@ TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
std::string expected;
};
std::vector<testIt> tests
{
{
"some text **bla** text testing **it** out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"
},
{
"some text __bla__ text testing __it__ out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"
},
std::vector<testIt> tests{
{"some text **bla** text testing **it** out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"},
{"some text __bla__ text testing __it__ out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"},
};
auto strongParser = std::make_shared<maddy::StrongParser>();
@@ -47,16 +42,11 @@ TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
std::string expected;
};
std::vector<testIt> tests
{
{
"some text *bla* text testing **it** out",
"some text *bla* text testing <strong>it</strong> out"
},
{
"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"
},
std::vector<testIt> tests{
{"some text *bla* text testing **it** out",
"some text *bla* text testing <strong>it</strong> out"},
{"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"},
};
auto strongParser = std::make_shared<maddy::StrongParser>();
@@ -76,16 +66,13 @@ TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode)
std::string expected;
};
std::vector<testIt> tests
{
std::vector<testIt> tests{
{
"some text **bla** `/**text**/` testing `**it**` out",
"some text **bla** `/**text**/` testing `**it**` out",
},
{
"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"
},
{"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"},
};
auto strongParser = std::make_shared<maddy::StrongParser>();

View File

@@ -15,19 +15,17 @@ class MADDY_TABLEPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::TableParser> tableParser;
void
SetUp() override
void SetUp() override
{
this->tableParser = std::make_shared<maddy::TableParser>(
nullptr,
nullptr
);
this->tableParser = std::make_shared<maddy::TableParser>(nullptr, nullptr);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_TABLEPARSER, IsStartingLineReturnsTrueWhenFacedWithTheBeginningOfATable)
TEST_F(
MADDY_TABLEPARSER, IsStartingLineReturnsTrueWhenFacedWithTheBeginningOfATable
)
{
ASSERT_EQ(true, maddy::TableParser::IsStartingLine("|table>"));
}
@@ -40,16 +38,21 @@ TEST_F(MADDY_TABLEPARSER, IsFinishedReturnsFalseInTheBeginning)
TEST_F(MADDY_TABLEPARSER, ItReplacesMarkdownWithAnHtmlTable)
{
std::vector<std::string> markdown = {
"|table>"
, "Left header|middle header|last header"
, "- | - | -"
, "cell 1|cell 2|cell 3"
, "cell 4|cell 5|cell 6"
, "- | - | -"
, "foot a|foot b|foot c"
, "|<table"
"|table>",
"Left header|middle header|last header",
"- | - | -",
"cell 1|cell 2|cell 3",
"cell 4|cell 5|cell 6",
"- | - | -",
"foot a|foot b|foot c",
"|<table"
};
std::string expected = "<table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell 2</td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table>";
std::string expected =
"<table><thead><tr><th>Left header</th><th>middle header</th><th>last "
"header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell 2</td><td>cell "
"3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell "
"6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot "
"c</td></tr></tfoot></table>";
for (std::string md : markdown)
{

View File

@@ -15,10 +15,10 @@ class MADDY_UNORDEREDLISTPARSER : public ::testing::Test
protected:
std::shared_ptr<maddy::UnorderedListParser> ulParser;
void
SetUp() override
void SetUp() override
{
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)>
getBlockParserForLineCallback = [](const std::string& line)
{
if (maddy::UnorderedListParser::IsStartingLine(line))
{
@@ -32,15 +32,17 @@ protected:
};
this->ulParser = std::make_shared<maddy::UnorderedListParser>(
nullptr,
getBlockParserForLineCallback
nullptr, getBlockParserForLineCallback
);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_UNORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
TEST_F(
MADDY_UNORDEREDLISTPARSER,
IsStartingLineReturnsTrueWhenFacedWithBeginningOfList
)
{
ASSERT_TRUE(maddy::UnorderedListParser::IsStartingLine("* a"));
}
@@ -53,16 +55,11 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
{
std::vector<std::string> markdown = {
"* a"
, "* b"
, "- c"
, "- d"
, "+ e"
, "+ f"
, "* g"
, ""
"* a", "* b", "- c", "- d", "+ e", "+ f", "* g", ""
};
std::string expected = "<ul><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</li></ul>";
std::string expected =
"<ul><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</"
"li></ul>";
for (std::string md : markdown)
{
@@ -80,17 +77,11 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
{
std::vector<std::string> markdown = {
"* a"
, " * d"
, " * e"
, "* b"
, " * c"
, " + x"
, " + y"
, " - z"
, ""
"* a", " * d", " * e", "* b", " * c", " + x", " + y", " - z", ""
};
std::string expected = "<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li><li>x</li><li>y</li><li>z</li></ul></li></ul>";
std::string expected =
"<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li><li>x</"
"li><li>y</li><li>z</li></ul></li></ul>";
for (std::string md : markdown)
{

View File

@@ -7,7 +7,8 @@
// -----------------------------------------------------------------------------
int main (int argc, char** argv) {
int main(int argc, char** argv)
{
::testing::GTEST_FLAG(throw_on_failure) = true;
::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();