mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 12:10:42 +02:00
moved tests to it's own directory
This commit is contained in:
8
src/tests/config.toml
Normal file
8
src/tests/config.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[general]
|
||||
lang = "en"
|
||||
title = "Blog"
|
||||
|
||||
[contact]
|
||||
author = "author"
|
||||
email = "email@example.com"
|
||||
signal = "signal url"
|
||||
BIN
src/tests/image.png
Normal file
BIN
src/tests/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 290 KiB |
2
src/tests/no_metadata_post.md
Normal file
2
src/tests/no_metadata_post.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# This markdown has no metadata.
|
||||
That's bad. Don't do it. It's for tests only.
|
||||
41
src/tests/post.md
Normal file
41
src/tests/post.md
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
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
|
||||
87
src/tests/tests.cpp
Normal file
87
src/tests/tests.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "../config.hpp"
|
||||
#include "../markdown.hpp"
|
||||
#include "../utils.hpp"
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
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("convert_string_to_set parses inline YAML string list") {
|
||||
const std::string input = "[\"haha\", \"dupa\", \"xdd\"]";
|
||||
const std::set<std::string> output = {"haha", "dupa", "xdd"};
|
||||
REQUIRE(convert_string_to_set(input) == output);
|
||||
}
|
||||
|
||||
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";
|
||||
std::string expected_date = "2026-01-01";
|
||||
std::string expected_title = "Example of a blog post";
|
||||
std::set<std::string> expected_tags = {"blog", "test", "lalilulelo"};
|
||||
|
||||
REQUIRE(result.author == expected_author);
|
||||
REQUIRE(result.date == expected_date);
|
||||
REQUIRE(result.title == expected_title);
|
||||
|
||||
for (const auto &tag : expected_tags) {
|
||||
REQUIRE(result.tags.count(tag));
|
||||
}
|
||||
}
|
||||
|
||||
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<Metadata> 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(<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>
|
||||
<h3>Look at this!</h3>
|
||||
<p><strong>This text is BOLD!</strong></p>
|
||||
<h2>Hello world!</h2>
|
||||
<pre><code class="language-cpp">#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello world!" << std::endl;
|
||||
}
|
||||
</code></pre>
|
||||
<p>This is super cool!</p>
|
||||
<h2>Time to link some random website!</h2>
|
||||
<p>This <a href="https://example.com">should be clickable</a></p>
|
||||
<h2>Image test</h2>
|
||||
<p><img src="./image.png" alt="this should show an image"></p>
|
||||
<h2>This is an ordered list</h2>
|
||||
<ol>
|
||||
<li>one</li>
|
||||
<li>six</li>
|
||||
<li>seven</li>
|
||||
</ol>
|
||||
<h2>This is an unordered one</h2>
|
||||
<ul>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
<li>six</li>
|
||||
<li>nine</li>
|
||||
</ul>
|
||||
)HTML";
|
||||
|
||||
REQUIRE(get_html(INPUT) == EXPECTED_OUTPUT);
|
||||
}
|
||||
Reference in New Issue
Block a user