Adds beginnings of BlogPageBuilder and associated classes
This commit is contained in:
parent
65aefe46ce
commit
1506f661c9
114 changed files with 4740 additions and 518 deletions
27
Tests/BlogPageBuilderTest.cpp
Normal file
27
Tests/BlogPageBuilderTest.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "../MacroDefinitions.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "../Src/BlogPageBuilder.h"
|
||||
#include "TestFileReaderUtil.h"
|
||||
|
||||
|
||||
TEST_CASE("BlogPageBuilder reads template file")
|
||||
{
|
||||
BlogPageBuilder* builder = new BlogPageBuilder(TEST_RESOURCE_FOLDER "/TestBlogPageTemplate.html");
|
||||
|
||||
std::string expectedOutcome = TestFileReaderUtil::readFile(TEST_RESOURCE_FOLDER "/TestBlogPageBlankExpectedOutcome.html");
|
||||
std::string outcome = builder->createPage(TEST_RESOURCE_FOLDER "/EmptyFile.html");
|
||||
|
||||
REQUIRE(expectedOutcome == outcome);
|
||||
}
|
||||
|
||||
TEST_CASE("BlogPageBuilder combines text with template")
|
||||
{
|
||||
BlogPageBuilder* builder = new BlogPageBuilder(TEST_RESOURCE_FOLDER "/TestBlogPageTemplate.html");
|
||||
|
||||
std::string expectedOutcome = TestFileReaderUtil::readFile(TEST_RESOURCE_FOLDER "/TestBlogPageExpectedOutcome.html");
|
||||
std::string outcome = builder->createPage(TEST_RESOURCE_FOLDER "/TestArticle.md");
|
||||
|
||||
REQUIRE(expectedOutcome == outcome);
|
||||
}
|
|
@ -1,16 +1,15 @@
|
|||
/*
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "../Src/BlogParser.cpp"
|
||||
#include "../Src/BlogParser.h"
|
||||
|
||||
TEST_CASE("Basic Test")
|
||||
TEST_CASE("Parser returns basic text")
|
||||
{
|
||||
BlogParser* parser = new BlogParser();
|
||||
REQUIRE(parser->ParseText("hello") == "hello");
|
||||
REQUIRE(parser->parse("hello") == "<p>hello</p>\n");
|
||||
}
|
||||
|
||||
TEST_CASE("Parser returns valid HTML with basic component")
|
||||
TEST_CASE("Parser returns valid HTML for headers")
|
||||
{
|
||||
BlogParser* parser = new BlogParser();
|
||||
REQUIRE(parser->ParseText("#header \n no header") == "<h1>header</h1>no header");
|
||||
REQUIRE(parser->parse("# header\nno header") == "<h1>header</h1>\n<p>no header</p>\n");
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -4,4 +4,11 @@ add_executable(tests test.cpp)
|
|||
|
||||
target_include_directories(tests PRIVATE ../Src)
|
||||
|
||||
|
||||
target_link_libraries(tests PRIVATE BlogParser)
|
||||
target_link_libraries(tests PRIVATE BlogPageBuilder)
|
||||
|
||||
target_link_libraries(tests PUBLIC md4c)
|
||||
target_link_libraries(tests PUBLIC md4c-html)
|
||||
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
|
|
28
Tests/TestFileReaderUtil.h
Normal file
28
Tests/TestFileReaderUtil.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
|
||||
class TestFileReaderUtil
|
||||
{
|
||||
public:
|
||||
static std::string readFile(std::string fileUrl)
|
||||
{
|
||||
std::ifstream file(fileUrl);
|
||||
std::stringstream fileCache;
|
||||
fileCache << file.rdbuf();
|
||||
|
||||
if (file.fail())
|
||||
{
|
||||
UNSCOPED_INFO("WARNING: File read failed");
|
||||
UNSCOPED_INFO("fileUrl: " + fileUrl);
|
||||
}
|
||||
|
||||
return fileCache.str();
|
||||
}
|
||||
};
|
|
@ -1,2 +1,4 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
//#include "BlogParserTest.cpp"
|
||||
|
||||
#include "BlogParserTest.cpp"
|
||||
#include "BlogPageBuilderTest.cpp"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue