From cf3b5025097946a9a5fa39730ae0907308573335 Mon Sep 17 00:00:00 2001 From: Szymon P Date: Thu, 8 Jan 2026 12:32:04 +0100 Subject: [PATCH] added formatter inject_html test --- src/formatter.cpp | 5 ++--- src/formatter.hpp | 7 +++++++ src/makefile | 2 +- src/tests/formatter.html | 11 +++++++++++ src/tests/tests.cpp | 20 ++++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/tests/formatter.html diff --git a/src/formatter.cpp b/src/formatter.cpp index a96845e..202013d 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -3,7 +3,8 @@ #include #include -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) { diff --git a/src/formatter.hpp b/src/formatter.hpp index e69de29..ee70c95 100644 --- a/src/formatter.hpp +++ b/src/formatter.hpp @@ -0,0 +1,7 @@ +#include + +// 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); diff --git a/src/makefile b/src/makefile index f14ae3e..ad44c4f 100644 --- a/src/makefile +++ b/src/makefile @@ -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 diff --git a/src/tests/formatter.html b/src/tests/formatter.html new file mode 100644 index 0000000..973e582 --- /dev/null +++ b/src/tests/formatter.html @@ -0,0 +1,11 @@ + + + + + + Document + + + {{replace_me}} + + diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index c8e269e..2daa9b1 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -1,4 +1,5 @@ #include "../config.hpp" +#include "../formatter.hpp" #include "../markdown.hpp" #include "../utils.hpp" #include @@ -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"( + + + + + Document + + + I'm replaced! + + +)"; + const std::string output = + inject_html_into_template(FILE_NAME, "{{replace_me}}", "I'm replaced!"); + REQUIRE(EXPECTED_OUTPUT == output); +}