#include "../config.hpp" #include "../formatter.hpp" #include "../markdown.hpp" #include "../utils.hpp" #include #include #include #include #include TEST_CASE("Checking config file read", "[config]") { const std::string FILE_NAME = "tests/config.toml"; Config config = get_config(FILE_NAME); REQUIRE(config.contact.author == "author"); REQUIRE(config.contact.email == "email@example.com"); REQUIRE(config.contact.signal == "signal url"); REQUIRE(config.general.lang == "en"); REQUIRE(config.general.title == "Blog"); } TEST_CASE("get_metadata function data correctness test") { const std::string FILE_NAME = "./tests/post.md"; Metadata result = get_metadata(FILE_NAME).value(); std::string expected_author = "joseph"; struct tm datetime = {0}; datetime.tm_year = 2026 - 1900; datetime.tm_mon = 1 - 1; datetime.tm_mday = 1; datetime.tm_isdst = 0; time_t expected_date = mktime(&datetime); std::string expected_title = "Example of a blog post"; std::vector expected_tags = {"blog", "test", "lalilulelo"}; REQUIRE(result.author == expected_author); REQUIRE(result.date == expected_date); REQUIRE(result.title == expected_title); REQUIRE(result.tags == expected_tags); } TEST_CASE("get_metadata function test with a file that doesn't have metadata") { const std::string FILE_NAME = ".tests/no_metadata_post.md"; std::optional result = get_metadata(FILE_NAME); REQUIRE(result == std::nullopt); } TEST_CASE("get_html function parsing test") { const std::string INPUT = "./tests/post.md"; const std::string EXPECTED_OUTPUT = R"HTML(

This is an example post

In this example we will do a couple of cool markdown things.

This is a h2 header

This text is written in italic!

Look at this!

This text is BOLD!

Hello world!

#include <iostream>

int main() {
    std::cout << "Hello world!" << std::endl;
}

This is super cool!

Time to link some random website!

This should be clickable

Image test

this should show an image

This is an ordered list

  1. one
  2. six
  3. seven

This is an unordered one

  • six
  • nine
  • six
  • nine
)HTML"; 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); }