made formatting files work

This commit is contained in:
2026-01-12 12:52:19 +01:00
parent 1a58577b3e
commit 19d86e8dc7
3 changed files with 103 additions and 62 deletions

View File

@@ -43,6 +43,46 @@ constexpr const char *formated_html = R"(<!DOCTYPE html>
</body>
</html>)";
constexpr const char *formatter_html_conditionally = R"(<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{if tag}}
<p>{{tag}}</p>
{{endif}}
</body>
</html>)";
constexpr const char *formated_html_conditionally = R"(<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>tag</p>
</body>
</html>)";
constexpr const char *formated_html_conditionally_empty = R"(<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>)";
constexpr const char *no_metadata_post_md = R"(# This markdown has no metadata.
That's bad. Don't do it. It's for tests only.)";
@@ -183,3 +223,21 @@ TEST_CASE("Test format_file function with correct data") {
"{{replace_me}}",
"I'm formatted!"));
}
TEST_CASE("Test format_file function with no templates") {
REQUIRE(TestFiles::formated_html ==
format_file(TestFiles::formated_html, "{{replace_me}}", "nothing"));
}
TEST_CASE("Test format_file_conditionally with tag") {
REQUIRE(TestFiles::formated_html_conditionally ==
format_file_conditionally(TestFiles::formatter_html_conditionally,
"{{if tag}}", "{{endif}}", "{{tag}}",
"tag"));
}
TEST_CASE("Test format_file_conditionally with empty tag") {
REQUIRE(TestFiles::formated_html_conditionally_empty ==
format_file_conditionally(TestFiles::formatter_html_conditionally,
"{{if tag}}", "{{endif}}", "{{tag}}", ""));
}