diff --git a/.gitignore b/.gitignore index 5c2c1a3..327fac9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ out/ posts/ +src/tests/tests *.o diff --git a/README.md b/README.md index c9bbfaa..eddc24c 100644 --- a/README.md +++ b/README.md @@ -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? Also pretty simple. You have: - `/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. - `/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. diff --git a/src/makefile b/src/makefile index f596499..934f001 100644 --- a/src/makefile +++ b/src/makefile @@ -2,6 +2,7 @@ CXX = g++ CXXFLAGS = -std=c++17 -Wall TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2 LIBS = -lmd4c-html +TEST_DIR = tests all: blog @@ -20,14 +21,14 @@ utils.o: utils.cpp utils.hpp markdown.o: markdown.cpp markdown.hpp $(CXX) $(CXXFLAGS) -c markdown.cpp -tests: tests.o config.o utils.o markdown.o - g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o tests $(TEST_LIBS) +tests.o: $(TEST_DIR)/tests.cpp config.hpp + $(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp -tests.o: tests.cpp config.hpp - $(CXX) $(CXXFLAGS) -c tests.cpp +tests: tests.o config.o utils.o markdown.o + g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o $(TEST_DIR)/tests $(TEST_LIBS) check: tests - ./tests + $(TEST_DIR)/tests clean: - rm -f *.o blog tests + rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests diff --git a/src/tests/config.toml b/src/tests/config.toml new file mode 100644 index 0000000..6cf6a90 --- /dev/null +++ b/src/tests/config.toml @@ -0,0 +1,8 @@ +[general] +lang = "en" +title = "Blog" + +[contact] +author = "author" +email = "email@example.com" +signal = "signal url" diff --git a/src/tests/image.png b/src/tests/image.png new file mode 100644 index 0000000..49abd93 Binary files /dev/null and b/src/tests/image.png differ diff --git a/examples/no_metadata_post.md b/src/tests/no_metadata_post.md similarity index 100% rename from examples/no_metadata_post.md rename to src/tests/no_metadata_post.md diff --git a/src/tests/post.md b/src/tests/post.md new file mode 100644 index 0000000..dfeaa5f --- /dev/null +++ b/src/tests/post.md @@ -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 + +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 diff --git a/src/tests.cpp b/src/tests/tests.cpp similarity index 85% rename from src/tests.cpp rename to src/tests/tests.cpp index ac5d076..214e5d8 100644 --- a/src/tests.cpp +++ b/src/tests/tests.cpp @@ -1,13 +1,13 @@ -#include "config.hpp" -#include "markdown.hpp" -#include "utils.hpp" +#include "../config.hpp" +#include "../markdown.hpp" +#include "../utils.hpp" #include #include #include #include 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); @@ -25,7 +25,7 @@ TEST_CASE("convert_string_to_set parses inline YAML string list") { } 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(); 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") { - const std::string FILE_NAME = "../examples/no_metadata_post.md"; + const std::string FILE_NAME = ".tests/no_metadata_post.md"; std::optional result = get_metadata(FILE_NAME); 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") { - const std::string INPUT = "../examples/post.md"; + 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