mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 12:10:42 +02:00
added formatter inject_html test
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
bool replace(std::string &str, const std::string &from, const std::string &to) {
|
||||
static bool replace(std::string &str, const std::string &from,
|
||||
const std::string &to) {
|
||||
size_t start_pos = str.find(from);
|
||||
if (start_pos == std::string::npos)
|
||||
return false;
|
||||
@@ -11,8 +12,6 @@ bool replace(std::string &str, const std::string &from, const std::string &to) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Change template from file into html
|
||||
// Return html in string
|
||||
std::string inject_html_into_template(const std::string &FILE_NAME,
|
||||
const std::string &TEMPLATE,
|
||||
const std::string &HTML) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <string>
|
||||
|
||||
// Change template from file into html
|
||||
// Return html in string
|
||||
std::string inject_html_into_template(const std::string &FILE_NAME,
|
||||
const std::string &TEMPLATE,
|
||||
const std::string &HTML);
|
||||
|
||||
@@ -22,7 +22,7 @@ markdown.o: markdown.cpp markdown.hpp
|
||||
$(CXX) $(CXXFLAGS) -c markdown.cpp
|
||||
|
||||
formatter.o: formatter.cpp formatter.hpp
|
||||
$(CXX) $(CXXFLAGS) -c formatter.hpp
|
||||
$(CXX) $(CXXFLAGS) -c formatter.cpp
|
||||
|
||||
tests.o: $(TEST_DIR)/tests.cpp config.hpp
|
||||
$(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp
|
||||
|
||||
11
src/tests/formatter.html
Normal file
11
src/tests/formatter.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{{replace_me}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../config.hpp"
|
||||
#include "../formatter.hpp"
|
||||
#include "../markdown.hpp"
|
||||
#include "../utils.hpp"
|
||||
#include <catch2/catch_all.hpp>
|
||||
@@ -83,3 +84,22 @@ int main() {
|
||||
|
||||
REQUIRE(get_html(INPUT) == EXPECTED_OUTPUT);
|
||||
}
|
||||
|
||||
TEST_CASE("formatter injection test") {
|
||||
const std::string FILE_NAME = "./tests/formatter.html";
|
||||
const std::string EXPECTED_OUTPUT = R"(<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
I'm replaced!
|
||||
</body>
|
||||
</html>
|
||||
)";
|
||||
const std::string output =
|
||||
inject_html_into_template(FILE_NAME, "{{replace_me}}", "I'm replaced!");
|
||||
REQUIRE(EXPECTED_OUTPUT == output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user