change test to take into account new io system

This commit is contained in:
2026-01-11 22:51:57 +01:00
parent 74b46f4923
commit bc9228cdc7
9 changed files with 82 additions and 34 deletions

View File

@@ -17,7 +17,9 @@ jobs:
run: |
sudo apt update
sudo apt install -y g++ catch2 libmd4c-dev libmd4c-html0-dev libtomlplusplus-dev
- name: make
run: make -C src
- name: make check
run: make check -C src
- name: make all
run: make all
- name: make test
run: make test
- name: make clean
run: make clean

2
.gitignore vendored
View File

@@ -3,5 +3,5 @@ posts/
src/build/
/src/blog
/src/tests
/src/cache/
/src/.cache/
*.o

Binary file not shown.

View File

@@ -7,10 +7,77 @@
#include <optional>
#include <string>
TEST_CASE("Checking config file read", "[config]") {
const std::string FILE_NAME = "test_files/config.toml";
namespace TestFiles {
constexpr const char *config_toml = R"([general]
lang = "en"
title = "Blog"
Config config = get_config(FILE_NAME);
[contact]
author = "author"
email = "email@example.com"
signal = "signal url")";
constexpr const char *formatter_html = 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>
{{replace_me}}
</body>
</html>)";
constexpr const char *no_metadata_post_md = R"(# This markdown has no metadata.
That's bad. Don't do it. It's for tests only.)";
constexpr const char *post_md = R"(---
[metadata]
author = "joseph"
date = 2026-01-01
title = "Example of a blog post"
tags = ["blog", "test", "lalilulelo"]
---
# 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!
```cpp
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
}
```
This is super cool!
## Time to link some random website!
This [should be clickable](https://example.com)
## Image test
![this should show an image](./image.png)
## This is an ordered list
1. one
2. six
3. seven
## This is an unordered one
- six
- nine
- six
- nine)";
} // namespace TestFiles
TEST_CASE("Checking config file read", "[config]") {
Config config = get_config(TestFiles::config_toml);
REQUIRE(config.contact.author == "author");
REQUIRE(config.contact.email == "email@example.com");
@@ -20,8 +87,7 @@ TEST_CASE("Checking config file read", "[config]") {
}
TEST_CASE("get_metadata function data correctness test") {
const std::string FILE_NAME = "./test_files/post.md";
Metadata result = get_metadata(FILE_NAME).value();
Metadata result = get_metadata(TestFiles::post_md).value();
std::string expected_author = "joseph";
struct tm datetime = {0};
@@ -41,14 +107,13 @@ TEST_CASE("get_metadata function data correctness test") {
}
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
const std::string FILE_NAME = ".test_files/no_metadata_post.md";
std::optional<Metadata> result = get_metadata(FILE_NAME);
std::optional<Metadata> result = get_metadata(TestFiles::no_metadata_post_md);
REQUIRE(result == std::nullopt);
}
TEST_CASE("get_html function parsing test") {
const std::string INPUT = "./test_files/post.md";
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
const std::string EXPECTED_OUTPUT =
R"HTML(<h1>This is an example post</h1>
<p>In this example we will do a couple of cool markdown things.</p>
<h2>This is a h2 header</h2>
<p><em>This text is written in italic!</em></p>
@@ -81,24 +146,5 @@ int main() {
</ul>
)HTML";
REQUIRE(get_html(INPUT) == EXPECTED_OUTPUT);
}
TEST_CASE("formatter injection test") {
const std::string FILE_NAME = "./test_files/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);
REQUIRE(get_html(TestFiles::post_md) == EXPECTED_OUTPUT);
}