duplikat dari
https://github.com/quitesimpleorg/qsmaddy.git
synced 2025-06-26 21:22:05 +02:00
initial release 1.0.0
This commit is contained in:
99
tests/maddy/test_maddy_checklistparser.cpp
Normal file
99
tests/maddy/test_maddy_checklistparser.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/checklistparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_CHECKLISTPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::ChecklistParser> clParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
||||
{
|
||||
if (maddy::ChecklistParser::IsStartingLine(line))
|
||||
{
|
||||
return std::static_pointer_cast<maddy::BlockParser>(
|
||||
std::make_shared<maddy::ChecklistParser>(nullptr, nullptr)
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<maddy::BlockParser> empty;
|
||||
return empty;
|
||||
};
|
||||
|
||||
this->clParser = std::make_shared<maddy::ChecklistParser>(
|
||||
nullptr,
|
||||
getBlockParserForLineCallback
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_CHECKLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
||||
{
|
||||
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [ ] a"));
|
||||
ASSERT_TRUE(maddy::ChecklistParser::IsStartingLine("- [x] b"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_CHECKLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(clParser->IsFinished());
|
||||
}
|
||||
|
||||
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>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
clParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(clParser->IsFinished());
|
||||
|
||||
std::stringstream& output(clParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
||||
|
||||
TEST_F(MADDY_CHECKLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"- [ ] 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>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
clParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(clParser->IsFinished());
|
||||
|
||||
std::stringstream& output(clParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
61
tests/maddy/test_maddy_codeblockparser.cpp
Normal file
61
tests/maddy/test_maddy_codeblockparser.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/codeblockparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_CODEBLOCKPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::CodeBlockParser> cbParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->cbParser = std::make_shared<maddy::CodeBlockParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_CODEBLOCKPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeSigns)
|
||||
{
|
||||
ASSERT_TRUE(maddy::CodeBlockParser::IsStartingLine("```"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_CODEBLOCKPARSER, IsFinishedReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(cbParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"```"
|
||||
, "some code"
|
||||
, "some other code"
|
||||
, "```"
|
||||
};
|
||||
|
||||
std::string expected = "<pre><code>\nsome code\nsome other code\n</code></pre>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
cbParser->AddLine(md);
|
||||
}
|
||||
ASSERT_TRUE(cbParser->IsFinished());
|
||||
|
||||
std::stringstream& output(cbParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
22
tests/maddy/test_maddy_emphasizedparser.cpp
Normal file
22
tests/maddy/test_maddy_emphasizedparser.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/emphasizedparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
|
||||
{
|
||||
std::string text = "some text *bla* text testing *it* out";
|
||||
std::string expected = "some text <em>bla</em> text testing <em>it</em> out";
|
||||
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
|
||||
|
||||
emphasizedParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
88
tests/maddy/test_maddy_headlineparser.cpp
Normal file
88
tests/maddy/test_maddy_headlineparser.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/headlineparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_HEADLINEPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::HeadlineParser> hlParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->hlParser = std::make_shared<maddy::HeadlineParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_HEADLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithOneToSixHashes)
|
||||
{
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("# a"));
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("## a"));
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("### a"));
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("#### a"));
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("##### a"));
|
||||
ASSERT_TRUE(maddy::HeadlineParser::IsStartingLine("###### a"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HEADLINEPARSER, IsFinishedAlwaysReturnsTrue)
|
||||
{
|
||||
ASSERT_TRUE(hlParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HEADLINEPARSER, ItReplacesMarkdownWithAnHtmlHeadline)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"# 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>"
|
||||
};
|
||||
|
||||
for (uint8_t i = 0; i < 6; ++i)
|
||||
{
|
||||
hlParser->AddLine(markdown[i]);
|
||||
std::stringstream& output(hlParser->GetResult());
|
||||
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected[i], outputString);
|
||||
hlParser->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HEADLINEPARSER, ItReplacesInvalidMarkdownNotWithAnHtmlHeadline)
|
||||
{
|
||||
std::string markdown = "####### a";
|
||||
std::string expected(markdown);
|
||||
|
||||
hlParser->AddLine(markdown);
|
||||
std::stringstream& output(hlParser->GetResult());
|
||||
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
64
tests/maddy/test_maddy_horizontallineparser.cpp
Normal file
64
tests/maddy/test_maddy_horizontallineparser.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/horizontallineparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_HORIZONTALLINEPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::HorizontalLineParser> hlParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->hlParser = std::make_shared<maddy::HorizontalLineParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_HORIZONTALLINEPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes)
|
||||
{
|
||||
ASSERT_TRUE(maddy::HorizontalLineParser::IsStartingLine("---"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HORIZONTALLINEPARSER, IsFinishedAlwaysReturnsTrue)
|
||||
{
|
||||
ASSERT_TRUE(hlParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HORIZONTALLINEPARSER, ItReplacesMarkdownWithAnHtmlLine)
|
||||
{
|
||||
std::string markdown = "---";
|
||||
std::string expected = "<hr/>";
|
||||
|
||||
hlParser->AddLine(markdown);
|
||||
std::stringstream& output(hlParser->GetResult());
|
||||
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
||||
|
||||
TEST_F(MADDY_HORIZONTALLINEPARSER, ItReplacesInvalidMarkdownNotWithAnHtmlLine)
|
||||
{
|
||||
std::string markdown = "--- ";
|
||||
std::string expected(markdown);
|
||||
|
||||
hlParser->AddLine(markdown);
|
||||
std::stringstream& output(hlParser->GetResult());
|
||||
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
44
tests/maddy/test_maddy_imageparser.cpp
Normal file
44
tests/maddy/test_maddy_imageparser.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/imageparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithAnImage)
|
||||
{
|
||||
std::string text = "Some text ";
|
||||
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);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
||||
|
||||
TEST(MADDY_IMAGEPARSER, ItReplacesMarkdownWithImages)
|
||||
{
|
||||
std::string text = "Some text  bla ";
|
||||
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);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
||||
|
||||
TEST(MADDY_IMAGEPARSER, ItReplacesNoLinkMarkdownWithImages)
|
||||
{
|
||||
std::string text = "Some text [Image Title](http://example.com)";
|
||||
std::string expected(text);
|
||||
auto imageParser = std::make_shared<maddy::ImageParser>();
|
||||
|
||||
imageParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
22
tests/maddy/test_maddy_inlinecodeparser.cpp
Normal file
22
tests/maddy/test_maddy_inlinecodeparser.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/inlinecodeparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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";
|
||||
auto emphasizedParser = std::make_shared<maddy::InlineCodeParser>();
|
||||
|
||||
emphasizedParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
50
tests/maddy/test_maddy_linkparser.cpp
Normal file
50
tests/maddy/test_maddy_linkparser.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/linkparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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>";
|
||||
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||
|
||||
linkParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
||||
|
||||
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>";
|
||||
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||
|
||||
linkParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
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
|
||||
TEST_F(DISABLED_MADDY_LINKPARSER, ItReplacesNoImageMarkdownWithLinks)
|
||||
{
|
||||
std::string text = "Some text ";
|
||||
std::string expected(text);
|
||||
auto linkParser = std::make_shared<maddy::LinkParser>();
|
||||
|
||||
linkParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
98
tests/maddy/test_maddy_orderedlistparser.cpp
Normal file
98
tests/maddy/test_maddy_orderedlistparser.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/orderedlistparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_ORDEREDLISTPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::OrderedListParser> olParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
||||
{
|
||||
if (maddy::OrderedListParser::IsStartingLine(line))
|
||||
{
|
||||
return std::static_pointer_cast<maddy::BlockParser>(
|
||||
std::make_shared<maddy::OrderedListParser>(nullptr, nullptr)
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<maddy::BlockParser> empty;
|
||||
return empty;
|
||||
};
|
||||
|
||||
this->olParser = std::make_shared<maddy::OrderedListParser>(
|
||||
nullptr,
|
||||
getBlockParserForLineCallback
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_ORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
||||
{
|
||||
ASSERT_TRUE(maddy::OrderedListParser::IsStartingLine("1. a"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_ORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(olParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlOrderedList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"1. a"
|
||||
, "* b"
|
||||
, ""
|
||||
};
|
||||
std::string expected = "<ol><li>a</li><li>b</li></ol>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
olParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(olParser->IsFinished());
|
||||
|
||||
std::stringstream& output(olParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
||||
|
||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"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>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
olParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(olParser->IsFinished());
|
||||
|
||||
std::stringstream& output(olParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
59
tests/maddy/test_maddy_paragraphparser.cpp
Normal file
59
tests/maddy/test_maddy_paragraphparser.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/paragraphparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_PARAGRAPHPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::ParagraphParser> pParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->pParser = std::make_shared<maddy::ParagraphParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_PARAGRAPHPARSER, IsStartingLineReturnsTrueWhenFacedWithThreeDashes)
|
||||
{
|
||||
ASSERT_TRUE(maddy::ParagraphParser::IsStartingLine("---"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_PARAGRAPHPARSER, IsFinishedReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(pParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_PARAGRAPHPARSER, ItReplacesMarkdownWithAnHtmlLine)
|
||||
{
|
||||
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)
|
||||
{
|
||||
pParser->AddLine(md);
|
||||
}
|
||||
ASSERT_TRUE(pParser->IsFinished());
|
||||
|
||||
std::stringstream& output(pParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
21
tests/maddy/test_maddy_parser.cpp
Normal file
21
tests/maddy/test_maddy_parser.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/parser.h"
|
||||
#include "maddy/test_maddy_parser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST(MADDY_PARSER, ItShouldParse)
|
||||
{
|
||||
auto parser = std::make_shared<maddy::Parser>();
|
||||
std::stringstream markdown(testMarkdown);
|
||||
|
||||
const std::string output = parser->Parse(markdown);
|
||||
|
||||
ASSERT_EQ(testHtml, output);
|
||||
}
|
70
tests/maddy/test_maddy_parser.h
Normal file
70
tests/maddy/test_maddy_parser.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
const std::string testMarkdown = "# This is a test\n\
|
||||
\n\
|
||||
This should result in a praragraph\n\
|
||||
it's that simple.\n\
|
||||
\n\
|
||||
* an unordered list\n\
|
||||
* with some **hierarchy**\n\
|
||||
1. and an *ordered*\n\
|
||||
* list\n\
|
||||
* directly\n\
|
||||
* inside\n\
|
||||
\n\
|
||||
```\n\
|
||||
var c = 'blub';\n\
|
||||
```\n\
|
||||
\n\
|
||||
> A Quote\n\
|
||||
>\n\
|
||||
> With some ~~text~~ blocks inside\n\
|
||||
>\n\
|
||||
> * even a list\n\
|
||||
> * should be\n\
|
||||
> * possible\n\
|
||||
>\n\
|
||||
\n\
|
||||
And well `inline code` should also work.\n\
|
||||
\n\
|
||||
## Another Headline\n\
|
||||
\n\
|
||||
And not to forget [link to progsource](http://progsource.de) should work.\n\
|
||||
And well - let's see how an image would be shown:\n\
|
||||
\n\
|
||||
\n\
|
||||
\n\
|
||||
---\n\
|
||||
\n\
|
||||
### and more headlines\n\
|
||||
\n\
|
||||
- [ ] how\n\
|
||||
- [ ] about\n\
|
||||
- [ ] a\n\
|
||||
- [x] nice\n\
|
||||
- [x] check\n\
|
||||
- [ ] list\n\
|
||||
\n\
|
||||
#### even a table\n\
|
||||
\n\
|
||||
|table>\n\
|
||||
Left header|middle header|last header\n\
|
||||
- | - | -\n\
|
||||
cell 1|cell **2**|cell 3\n\
|
||||
cell 4|cell 5|cell 6\n\
|
||||
- | - | -\n\
|
||||
foot a|foot b|foot c\n\
|
||||
|<table\n\
|
||||
\n\
|
||||
##### h5\n\
|
||||
###### h6\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 unordered 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/><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>";
|
62
tests/maddy/test_maddy_quoteparser.cpp
Normal file
62
tests/maddy/test_maddy_quoteparser.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/quoteparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_QUOTEPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::QuoteParser> quoteParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->quoteParser = std::make_shared<maddy::QuoteParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_QUOTEPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfAQuote)
|
||||
{
|
||||
ASSERT_TRUE(maddy::QuoteParser::IsStartingLine("> a"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_QUOTEPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(quoteParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_QUOTEPARSER, ItReplacesMarkdownWithAnHtmlBlockQuote)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"> a"
|
||||
, "> b"
|
||||
, ">"
|
||||
, "> c"
|
||||
, ""
|
||||
};
|
||||
std::string expected = "<blockquote>a b c </blockquote>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
quoteParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(quoteParser->IsFinished());
|
||||
|
||||
std::stringstream& output(quoteParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
22
tests/maddy/test_maddy_strikethroughparser.cpp
Normal file
22
tests/maddy/test_maddy_strikethroughparser.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/strikethroughparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST(MADDY_STRIKETHROUGHPARSER, ItReplacesMarkdownWithStrikeThroughHTML)
|
||||
{
|
||||
std::string text = "some text ~~bla~~ text testing ~~it~~ out";
|
||||
std::string expected = "some text <s>bla</s> text testing <s>it</s> out";
|
||||
auto strikeThroughParser = std::make_shared<maddy::StrikeThroughParser>();
|
||||
|
||||
strikeThroughParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
33
tests/maddy/test_maddy_strongparser.cpp
Normal file
33
tests/maddy/test_maddy_strongparser.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/strongparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
|
||||
{
|
||||
std::string text = "some text **bla** text testing **it** out";
|
||||
std::string expected = "some text <strong>bla</strong> text testing <strong>it</strong> out";
|
||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||
|
||||
strongParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
||||
|
||||
TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
|
||||
{
|
||||
std::string text = "some text *bla* text testing **it** out";
|
||||
std::string expected = "some text *bla* text testing <strong>it</strong> out";
|
||||
auto strongParser = std::make_shared<maddy::StrongParser>();
|
||||
|
||||
strongParser->Parse(text);
|
||||
|
||||
ASSERT_EQ(expected, text);
|
||||
}
|
66
tests/maddy/test_maddy_tableparser.cpp
Normal file
66
tests/maddy/test_maddy_tableparser.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/tableparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_TABLEPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::TableParser> tableParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
this->tableParser = std::make_shared<maddy::TableParser>(
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_TABLEPARSER, IsStartingLineReturnsTrueWhenFacedWithTheBeginningOfATable)
|
||||
{
|
||||
ASSERT_EQ(true, maddy::TableParser::IsStartingLine("|table>"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_TABLEPARSER, IsFinishedReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(tableParser->IsFinished());
|
||||
}
|
||||
|
||||
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"
|
||||
};
|
||||
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)
|
||||
{
|
||||
tableParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(tableParser->IsFinished());
|
||||
|
||||
std::stringstream& output(tableParser->GetResult());
|
||||
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
98
tests/maddy/test_maddy_unorderedlistparser.cpp
Normal file
98
tests/maddy/test_maddy_unorderedlistparser.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "maddy/unorderedlistparser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MADDY_UNORDEREDLISTPARSER : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<maddy::UnorderedListParser> ulParser;
|
||||
|
||||
void
|
||||
SetUp() override
|
||||
{
|
||||
std::function<std::shared_ptr<maddy::BlockParser>(const std::string& line)> getBlockParserForLineCallback = [](const std::string& line)
|
||||
{
|
||||
if (maddy::UnorderedListParser::IsStartingLine(line))
|
||||
{
|
||||
return std::static_pointer_cast<maddy::BlockParser>(
|
||||
std::make_shared<maddy::UnorderedListParser>(nullptr, nullptr)
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<maddy::BlockParser> empty;
|
||||
return empty;
|
||||
};
|
||||
|
||||
this->ulParser = std::make_shared<maddy::UnorderedListParser>(
|
||||
nullptr,
|
||||
getBlockParserForLineCallback
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
TEST_F(MADDY_UNORDEREDLISTPARSER, IsStartingLineReturnsTrueWhenFacedWithBeginningOfList)
|
||||
{
|
||||
ASSERT_TRUE(maddy::UnorderedListParser::IsStartingLine("* a"));
|
||||
}
|
||||
|
||||
TEST_F(MADDY_UNORDEREDLISTPARSER, IsFinishedAlwaysReturnsFalseInTheBeginning)
|
||||
{
|
||||
ASSERT_FALSE(ulParser->IsFinished());
|
||||
}
|
||||
|
||||
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"* a"
|
||||
, "* b"
|
||||
, ""
|
||||
};
|
||||
std::string expected = "<ul><li>a</li><li>b</li></ul>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
ulParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(ulParser->IsFinished());
|
||||
|
||||
std::stringstream& output(ulParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
||||
|
||||
TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"* a"
|
||||
, " * d"
|
||||
, " * e"
|
||||
, "* b"
|
||||
, " * c"
|
||||
, ""
|
||||
};
|
||||
std::string expected = "<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li></ul></li></ul>";
|
||||
|
||||
for (std::string md : markdown)
|
||||
{
|
||||
ulParser->AddLine(md);
|
||||
}
|
||||
|
||||
ASSERT_TRUE(ulParser->IsFinished());
|
||||
|
||||
std::stringstream& output(ulParser->GetResult());
|
||||
const std::string& outputString = output.str();
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
14
tests/main.cpp
Normal file
14
tests/main.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
::testing::GTEST_FLAG(throw_on_failure) = false;
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Reference in New Issue
Block a user