mirror of
https://github.com/pantor/inja.git
synced 2026-05-17 17:55:23 +00:00
move unit tests to doctest
This commit is contained in:
+12
-10
@@ -1,6 +1,6 @@
|
||||
// Copyright (c) 2019 Pantor. All rights reserved.
|
||||
|
||||
#include "catch/catch.hpp"
|
||||
#include "doctest/doctest.h"
|
||||
#include "inja/inja.hpp"
|
||||
|
||||
|
||||
@@ -14,22 +14,24 @@ TEST_CASE("loading") {
|
||||
json data;
|
||||
data["name"] = "Jeff";
|
||||
|
||||
SECTION("Files should be loaded") {
|
||||
SUBCASE("Files should be loaded") {
|
||||
CHECK(env.load_file(test_file_directory + "simple.txt") == "Hello {{ name }}.");
|
||||
}
|
||||
|
||||
SECTION("Files should be rendered") {
|
||||
SUBCASE("Files should be rendered") {
|
||||
CHECK(env.render_file(test_file_directory + "simple.txt", data) == "Hello Jeff.");
|
||||
}
|
||||
|
||||
SECTION("File includes should be rendered") {
|
||||
SUBCASE("File includes should be rendered") {
|
||||
CHECK(env.render_file(test_file_directory + "include.txt", data) == "Answer: Hello Jeff.");
|
||||
}
|
||||
|
||||
SECTION("File error should throw") {
|
||||
SUBCASE("File error should throw") {
|
||||
std::string path(test_file_directory + "does-not-exist");
|
||||
CHECK_THROWS_WITH(env.load_file(path), "[inja.exception.file_error] failed accessing file at '" + path + "'");
|
||||
CHECK_THROWS_WITH(env.load_json(path), "[inja.exception.file_error] failed accessing file at '" + path + "'");
|
||||
|
||||
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());
|
||||
CHECK_THROWS_WITH(env.load_json(path), file_error_message.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ TEST_CASE("complete-files") {
|
||||
inja::Environment env {test_file_directory};
|
||||
|
||||
for (std::string test_name : {"simple-file", "nested", "nested-line", "html"}) {
|
||||
SECTION(test_name) {
|
||||
SUBCASE(test_name.c_str()) {
|
||||
CHECK(env.render_file_with_json_file(test_name + "/template.txt", test_name + "/data.json") == env.load_file(test_name + "/result.txt"));
|
||||
}
|
||||
}
|
||||
@@ -49,7 +51,7 @@ TEST_CASE("complete-files-whitespace-control") {
|
||||
env.set_lstrip_blocks(true);
|
||||
|
||||
for (std::string test_name : {"nested-whitespace"}) {
|
||||
SECTION(test_name) {
|
||||
SUBCASE(test_name.c_str()) {
|
||||
CHECK(env.render_file_with_json_file(test_name + "/template.txt", test_name + "/data.json") == env.load_file(test_name + "/result.txt"));
|
||||
}
|
||||
}
|
||||
@@ -61,7 +63,7 @@ TEST_CASE("global-path") {
|
||||
json data;
|
||||
data["name"] = "Jeff";
|
||||
|
||||
SECTION("Files should be written") {
|
||||
SUBCASE("Files should be written") {
|
||||
env.write("simple.txt", data, "global-path-result.txt");
|
||||
CHECK(env_result.load_file("global-path-result.txt") == "Hello Jeff.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user