mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-10-28 11:10:40 +01:00
Merge pull request #2 from szymon-jozef/refactor/tests
Moved tests into it's own directory for better readability"
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
out/
|
out/
|
||||||
posts/
|
posts/
|
||||||
|
src/tests/tests
|
||||||
*.o
|
*.o
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ From there you can rsync/push it to your server or do whatever you want to do wi
|
|||||||
# How does the directory structure work?
|
# How does the directory structure work?
|
||||||
Also pretty simple. You have:
|
Also pretty simple. You have:
|
||||||
- `/config` for config files. Initially empty so you need to copy it from example dir or make one yourself.
|
- `/config` for config files. Initially empty so you need to copy it from example dir or make one yourself.
|
||||||
- `/examples` example of configuration files. Tests are dependent on it so don't edit the content of these files! You can copy it to `/config` and edit it there.
|
- `/examples` example of configuration files. You can copy it to `/config` and edit it there.
|
||||||
- `/out` for processed site.
|
- `/out` for processed site.
|
||||||
- `/posts` here you write your blog posts. Every file should be in markdown format, metadata included!.
|
- `/posts` here you write your blog posts. Every file should be in markdown format, metadata included!.
|
||||||
- `/src` for cpp files. Here's where you run the binary to translate your markdown posts into html.
|
- `/src` for cpp files. Here's where you run the binary to translate your markdown posts into html.
|
||||||
|
|||||||
13
src/makefile
13
src/makefile
@@ -2,6 +2,7 @@ CXX = g++
|
|||||||
CXXFLAGS = -std=c++17 -Wall
|
CXXFLAGS = -std=c++17 -Wall
|
||||||
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
||||||
LIBS = -lmd4c-html
|
LIBS = -lmd4c-html
|
||||||
|
TEST_DIR = tests
|
||||||
|
|
||||||
all: blog
|
all: blog
|
||||||
|
|
||||||
@@ -20,14 +21,14 @@ utils.o: utils.cpp utils.hpp
|
|||||||
markdown.o: markdown.cpp markdown.hpp
|
markdown.o: markdown.cpp markdown.hpp
|
||||||
$(CXX) $(CXXFLAGS) -c markdown.cpp
|
$(CXX) $(CXXFLAGS) -c markdown.cpp
|
||||||
|
|
||||||
tests: tests.o config.o utils.o markdown.o
|
tests.o: $(TEST_DIR)/tests.cpp config.hpp
|
||||||
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o tests $(TEST_LIBS)
|
$(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp
|
||||||
|
|
||||||
tests.o: tests.cpp config.hpp
|
tests: tests.o config.o utils.o markdown.o
|
||||||
$(CXX) $(CXXFLAGS) -c tests.cpp
|
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o $(TEST_DIR)/tests $(TEST_LIBS)
|
||||||
|
|
||||||
check: tests
|
check: tests
|
||||||
./tests
|
$(TEST_DIR)/tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o blog tests
|
rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests
|
||||||
|
|||||||
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 |
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
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "config.hpp"
|
#include "../config.hpp"
|
||||||
#include "markdown.hpp"
|
#include "../markdown.hpp"
|
||||||
#include "utils.hpp"
|
#include "../utils.hpp"
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_all.hpp>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
TEST_CASE("Checking config file read", "[config]") {
|
TEST_CASE("Checking config file read", "[config]") {
|
||||||
const std::string FILE_NAME = "../examples/config.toml";
|
const std::string FILE_NAME = "tests/config.toml";
|
||||||
|
|
||||||
Config config = get_config(FILE_NAME);
|
Config config = get_config(FILE_NAME);
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ TEST_CASE("convert_string_to_set parses inline YAML string list") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("get_metadata function data correctness test") {
|
TEST_CASE("get_metadata function data correctness test") {
|
||||||
const std::string FILE_NAME = "../examples/post.md";
|
const std::string FILE_NAME = "./tests//post.md";
|
||||||
Metadata result = get_metadata(FILE_NAME).value();
|
Metadata result = get_metadata(FILE_NAME).value();
|
||||||
|
|
||||||
std::string expected_author = "joseph";
|
std::string expected_author = "joseph";
|
||||||
@@ -43,16 +43,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 = "../examples/no_metadata_post.md";
|
const std::string FILE_NAME = ".tests/no_metadata_post.md";
|
||||||
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
||||||
REQUIRE(result == std::nullopt);
|
REQUIRE(result == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* theres to much testing stuff in examples
|
|
||||||
* i need to move tests to some other directory with testing files
|
|
||||||
*/
|
|
||||||
TEST_CASE("get_html function parsing test") {
|
TEST_CASE("get_html function parsing test") {
|
||||||
const std::string INPUT = "../examples/post.md";
|
const std::string INPUT = "./tests/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>
|
<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>
|
||||||
Reference in New Issue
Block a user