mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 12:10:42 +02:00
change test to take into account new io system
This commit is contained in:
10
.github/workflows/c-cpp.yml
vendored
10
.github/workflows/c-cpp.yml
vendored
@@ -17,7 +17,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y g++ catch2 libmd4c-dev libmd4c-html0-dev libtomlplusplus-dev
|
sudo apt install -y g++ catch2 libmd4c-dev libmd4c-html0-dev libtomlplusplus-dev
|
||||||
- name: make
|
- name: make all
|
||||||
run: make -C src
|
run: make all
|
||||||
- name: make check
|
- name: make test
|
||||||
run: make check -C src
|
run: make test
|
||||||
|
- name: make clean
|
||||||
|
run: make clean
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,5 +3,5 @@ posts/
|
|||||||
src/build/
|
src/build/
|
||||||
/src/blog
|
/src/blog
|
||||||
/src/tests
|
/src/tests
|
||||||
/src/cache/
|
/src/.cache/
|
||||||
*.o
|
*.o
|
||||||
|
|||||||
BIN
src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx
Normal file
BIN
src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx
Normal file
BIN
src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx
Normal file
BIN
src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx
Normal file
BIN
src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx
Normal file
BIN
src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx
Normal file
BIN
src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx
Normal file
Binary file not shown.
104
src/tests.cpp
104
src/tests.cpp
@@ -7,10 +7,77 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
TEST_CASE("Checking config file read", "[config]") {
|
namespace TestFiles {
|
||||||
const std::string FILE_NAME = "test_files/config.toml";
|
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 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.author == "author");
|
||||||
REQUIRE(config.contact.email == "email@example.com");
|
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") {
|
TEST_CASE("get_metadata function data correctness test") {
|
||||||
const std::string FILE_NAME = "./test_files/post.md";
|
Metadata result = get_metadata(TestFiles::post_md).value();
|
||||||
Metadata result = get_metadata(FILE_NAME).value();
|
|
||||||
|
|
||||||
std::string expected_author = "joseph";
|
std::string expected_author = "joseph";
|
||||||
struct tm datetime = {0};
|
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") {
|
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(TestFiles::no_metadata_post_md);
|
||||||
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
|
||||||
REQUIRE(result == std::nullopt);
|
REQUIRE(result == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("get_html function parsing test") {
|
TEST_CASE("get_html function parsing test") {
|
||||||
const std::string INPUT = "./test_files/post.md";
|
const std::string EXPECTED_OUTPUT =
|
||||||
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
|
R"HTML(<h1>This is an example post</h1>
|
||||||
<p>In this example we will do a couple of cool markdown things.</p>
|
<p>In this example we will do a couple of cool markdown things.</p>
|
||||||
<h2>This is a h2 header</h2>
|
<h2>This is a h2 header</h2>
|
||||||
<p><em>This text is written in italic!</em></p>
|
<p><em>This text is written in italic!</em></p>
|
||||||
@@ -81,24 +146,5 @@ int main() {
|
|||||||
</ul>
|
</ul>
|
||||||
)HTML";
|
)HTML";
|
||||||
|
|
||||||
REQUIRE(get_html(INPUT) == EXPECTED_OUTPUT);
|
REQUIRE(get_html(TestFiles::post_md) == 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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user