2022-01-01 18:46:31 +00:00
|
|
|
#include "MarkdownParser.h"
|
2022-12-01 17:13:54 +00:00
|
|
|
|
2022-01-01 18:46:31 +00:00
|
|
|
#include "File.h"
|
2022-12-01 17:13:54 +00:00
|
|
|
|
|
|
|
#include "HtmlDocument.h"
|
|
|
|
#include "MarkdownDocument.h"
|
|
|
|
#include "MarkdownConverter.h"
|
2022-12-05 17:50:49 +00:00
|
|
|
#include "MarkdownElement.h"
|
2022-01-01 18:46:31 +00:00
|
|
|
#include "HtmlWriter.h"
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
#include "TestFramework.h"
|
2022-12-01 10:52:48 +00:00
|
|
|
#include "TestUtils.h"
|
2022-11-29 18:00:19 +00:00
|
|
|
|
2022-12-06 18:02:43 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
TEST_CASE(TestMarkdownParser, "[web]")
|
2022-01-01 18:46:31 +00:00
|
|
|
{
|
2022-12-01 10:52:48 +00:00
|
|
|
File md_file(TestUtils::getTestDataDir() / "sample_markdown.md");
|
|
|
|
const auto md_content = md_file.readText();
|
2022-01-01 18:46:31 +00:00
|
|
|
|
|
|
|
MarkdownParser parser;
|
2022-12-01 17:13:54 +00:00
|
|
|
auto md_doc = parser.run(md_content);
|
2022-01-01 18:46:31 +00:00
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<MarkdownElement::Type> expected_top_level = {
|
2022-12-06 18:02:43 +00:00
|
|
|
MarkdownElement::Type::HEADING,
|
|
|
|
MarkdownElement::Type::PARAGRAPH,
|
|
|
|
MarkdownElement::Type::HEADING,
|
|
|
|
MarkdownElement::Type::PARAGRAPH,
|
|
|
|
MarkdownElement::Type::MULTILINE_QUOTE,
|
|
|
|
MarkdownElement::Type::PARAGRAPH,
|
|
|
|
MarkdownElement::Type::HEADING,
|
|
|
|
MarkdownElement::Type::PARAGRAPH
|
|
|
|
};
|
|
|
|
|
|
|
|
REQUIRE(expected_top_level.size() <= md_doc->getNumElements());
|
|
|
|
for(unsigned idx=0; idx<expected_top_level.size(); idx++)
|
|
|
|
{
|
|
|
|
REQUIRE(md_doc->getElement(idx)->getType() == expected_top_level[idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkdownConverter converter;
|
|
|
|
auto html = converter.convert(md_doc.get());
|
|
|
|
|
|
|
|
HtmlWriter writer;
|
|
|
|
const auto html_string = writer.toString(html.get());
|
|
|
|
|
|
|
|
File html_file(TestUtils::getTestOutputDir(__FILE__) / "TestMarkdownParser.html");
|
|
|
|
html_file.writeText(html_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(TestMarkdownParser_Simple, "[web]")
|
|
|
|
{
|
|
|
|
File md_file(TestUtils::getTestDataDir() / "simple_markdown.md");
|
|
|
|
const auto md_content = md_file.readText();
|
|
|
|
|
|
|
|
REQUIRE(!md_content.empty());
|
|
|
|
|
|
|
|
MarkdownParser parser;
|
|
|
|
auto md_doc = parser.run(md_content);
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<MarkdownElement::Type> expected_top_level = {
|
2022-12-06 18:02:43 +00:00
|
|
|
MarkdownElement::Type::PARAGRAPH,
|
|
|
|
MarkdownElement::Type::BULLET_LIST};
|
|
|
|
|
|
|
|
//REQUIRE(expected_top_level.size() <= md_doc->getNumElements());
|
|
|
|
for(unsigned idx=0; idx<expected_top_level.size(); idx++)
|
|
|
|
{
|
|
|
|
//REQUIRE(md_doc->getElement(idx)->getType() == expected_top_level[idx]);
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:13:54 +00:00
|
|
|
MarkdownConverter converter;
|
|
|
|
auto html = converter.convert(md_doc.get());
|
2022-01-01 18:46:31 +00:00
|
|
|
|
|
|
|
HtmlWriter writer;
|
2022-12-01 11:49:57 +00:00
|
|
|
const auto html_string = writer.toString(html.get());
|
2022-01-01 18:46:31 +00:00
|
|
|
|
2022-12-06 18:02:43 +00:00
|
|
|
File html_file(TestUtils::getTestOutputDir(__FILE__) / "TestMarkdownParser_simple.html");
|
2022-12-01 10:52:48 +00:00
|
|
|
html_file.writeText(html_string);
|
2022-01-01 18:46:31 +00:00
|
|
|
}
|