move tests to std::filesystem::path

This commit is contained in:
pantor
2025-03-31 23:22:36 +02:00
parent 804823dbca
commit 65aa8a669d
4 changed files with 14 additions and 12 deletions

View File

@@ -5,12 +5,12 @@
inja::Environment env;
const std::string test_file_directory {"../test/data/benchmark/"};
const std::filesystem::path test_file_directory {"../test/data/benchmark/"};
const auto small_data = env.load_json(test_file_directory + "small_data.json");
const auto large_data = env.load_json(test_file_directory + "large_data.json");
const std::string medium_template = env.load_file(test_file_directory + "medium_template.txt");
const std::string large_template = env.load_file(test_file_directory + "large_template.txt");
const auto small_data = env.load_json(test_file_directory / "small_data.json");
const auto large_data = env.load_json(test_file_directory / "large_data.json");
const std::string medium_template = env.load_file(test_file_directory / "medium_template.txt");
const std::string large_template = env.load_file(test_file_directory / "large_template.txt");
BENCHMARK(SmallDataMediumTemplate, render, 5, 30) {
env.render(medium_template, small_data);

View File

@@ -4,6 +4,6 @@
#include <string>
#include <doctest/doctest.h>
extern const std::string test_file_directory;
extern const std::filesystem::path test_file_directory;
#endif // INCLUDE_TEST_COMMON_HPP_

View File

@@ -10,19 +10,19 @@ TEST_CASE("loading") {
data["name"] = "Jeff";
SUBCASE("Files should be loaded") {
CHECK(env.load_file(test_file_directory + "simple.txt") == "Hello {{ name }}.");
CHECK(env.load_file(test_file_directory / "simple.txt") == "Hello {{ name }}.");
}
SUBCASE("Files should be rendered") {
CHECK(env.render_file(test_file_directory + "simple.txt", data) == "Hello Jeff.");
CHECK(env.render_file(test_file_directory / "simple.txt", data) == "Hello Jeff.");
}
SUBCASE("File includes should be rendered") {
CHECK(env.render_file(test_file_directory + "include.txt", data) == "Answer: Hello Jeff.");
CHECK(env.render_file(test_file_directory / "include.txt", data) == "Answer: Hello Jeff.");
}
SUBCASE("File error should throw") {
std::string path(test_file_directory + "does-not-exist");
std::string path(test_file_directory / "does-not-exist");
std::string file_error_message = "[inja.exception.file_error] failed accessing file at '" + path + "'";
CHECK_THROWS_WITH(env.load_file(path), file_error_message.c_str());
@@ -98,7 +98,7 @@ TEST_CASE("include-in-memory-and-file-template") {
inja::json data;
data["name"] = "Jeff";
std::string error_message = "[inja.exception.file_error] failed accessing file at '" + test_file_directory + "body'";
std::string error_message = "[inja.exception.file_error] failed accessing file at '" + test_file_directory.string() + "/body'";
CHECK_THROWS_WITH(env.render_file("include-both.txt", data), error_message.c_str());
const auto parsed_body_template = env.parse("Bye {{ name }}.");

View File

@@ -4,6 +4,8 @@
#define JSON_USE_IMPLICIT_CONVERSIONS 0
#define JSON_NO_IO 1
#include <filesystem>
#include "test-files.cpp"
#include "test-functions.cpp"
#include "test-renderer.cpp"
@@ -12,4 +14,4 @@
#define xstr(s) str(s)
#define str(s) #s
const std::string test_file_directory { xstr(__TEST_DIR__)"/data/" };
const std::filesystem::path test_file_directory { std::filesystem::path(xstr(__TEST_DIR__)) / "data" };