-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frantisek Boranek
committed
Sep 19, 2018
1 parent
5e3f50e
commit 375f29e
Showing
11 changed files
with
411 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Teng -- a general purpose templating engine. | ||
# Copyright (C) 2018 Seznam.cz, a.s. | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
# | ||
# Seznam.cz, a.s. | ||
# Naskove 1, Praha 5, 15000, Czech Republic | ||
# http://www.seznam.cz, mailto:teng@firma.seznam.cz | ||
# | ||
|
||
AM_LDFLAGS = -L@top_srcdir@/src $(BOOST_LDFLAGS) | ||
AM_CPPFLAGS = -std=c++14 -I$(top_srcdir)/src $(BOOST_CPPFLAGS) -DBOOST_TEST_DYN_LINK | ||
LDADD = -lteng ${BOOST_SYSTEM_LIB} ${BOOST_FILESYSTEM_LIB} ${BOOST_UNIT_TEST_FRAMEWORK_LIB} | ||
|
||
|
||
# test programs | ||
check_PROGRAMS = | ||
|
||
test_base_SOURCES = test_base.cc | ||
test_filesystem_SOURCES = test_filesystem.cc | ||
|
||
if CPP14 | ||
check_PROGRAMS += test_base test_filesystem | ||
else | ||
check_PROGRAMS += | ||
endif !CPP14 | ||
|
||
AM_COLOR_TESTS = always | ||
TESTS = $(check_PROGRAMS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<head> | ||
<title>Example page: ${title}</title> | ||
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<html> | ||
<?teng include file="common-head.html" ?> | ||
<body> | ||
<p><?teng include file="subdir/paragraph.html" ?></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Paragraph: ${title} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#define BOOST_TEST_MODULE base_tests | ||
|
||
#include "test_utils.h" | ||
|
||
#include <boost/filesystem.hpp> | ||
|
||
const std::string result_1 = R"__( <head> | ||
<title>Example page: Title</title> | ||
</head>)__"; | ||
|
||
const std::string result_2 = R"__( <head> | ||
<title>Example page: </title> | ||
</head>)__"; | ||
|
||
const std::string result_3 = R"__(<html> | ||
<head> | ||
<title>Example page: Title</title> | ||
</head> | ||
<body> | ||
<p>Paragraph: Title</p> | ||
</body> | ||
</html>)__"; | ||
|
||
const std::string result_4 = R"__(<html> | ||
<head> | ||
<title>Example page: </title> | ||
</head> | ||
<body> | ||
<p>Paragraph: </p> | ||
</body> | ||
</html>)__"; | ||
|
||
std::string createAbsPath(const std::string& root, const std::string& filename) | ||
{ | ||
return (!root.empty() && root[0] == '/') | ||
? (boost::filesystem::path(root) / filename).string() | ||
: (boost::filesystem::current_path() / root / filename).string(); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_include_ok) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
BOOST_CHECK_EQUAL( | ||
generate(teng, "<?teng include file=\"common-head.html\" ?>", *createFragmentTitle(), err), | ||
result_1); | ||
BOOST_CHECK_EQUAL(err.count(), 0); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_include_warning) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
BOOST_CHECK_EQUAL( | ||
generate(teng, "<?teng include file=\"common-head.html\" ?>", *createFragment(), err), | ||
result_2); | ||
BOOST_REQUIRE_EQUAL(err.count(), 1); | ||
BOOST_CHECK_EQUAL(err.getEntries().front().getLogLine(), | ||
"common-head.html(2,37) Warning: Runtime: Variable '.title' is undefined\n"); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_include_missing) | ||
{ | ||
Teng::Teng_t teng("no-directory", 0); | ||
Teng::Error_t err; | ||
|
||
const std::string absPath = createAbsPath("no-directory", "common-head.html"); | ||
|
||
BOOST_CHECK_EQUAL( | ||
generate(teng, "<?teng include file=\"common-head.html\" ?>", *createFragmentTitle(), err), | ||
""); | ||
BOOST_REQUIRE_EQUAL(err.count(), 2); | ||
BOOST_CHECK_EQUAL(err.getEntries()[0].getLogLine(), | ||
"(no file)(1,41) Error: Cannot open input file '" + absPath | ||
+ "' (No such file or directory)\n"); | ||
BOOST_CHECK_EQUAL(err.getEntries()[1].getLogLine(), | ||
"common-head.html(1,0) Error: Cannot stat file '" + absPath | ||
+ "' (No such file or directory)\n"); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_file_ok) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
BOOST_CHECK_EQUAL(generateFromFile(teng, "common-head.html", *createFragmentTitle(), err), | ||
result_1); | ||
BOOST_REQUIRE_EQUAL(err.count(), 0); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_file_missing) | ||
{ | ||
Teng::Teng_t teng("no-directory", 0); | ||
Teng::Error_t err; | ||
|
||
const std::string absPath = createAbsPath("no-directory", "common-head.html"); | ||
|
||
BOOST_CHECK_EQUAL(generateFromFile(teng, "common-head.html", *createFragmentTitle(), err), ""); | ||
BOOST_REQUIRE_EQUAL(err.count(), 2); | ||
BOOST_CHECK_EQUAL(err.getEntries()[0].getLogLine(), | ||
"(no file) Error: Cannot stat file '" + absPath | ||
+ "' (No such file or directory)\n"); | ||
BOOST_CHECK_EQUAL(err.getEntries()[1].getLogLine(), | ||
"(no file) Error: Cannot open input file '" + absPath | ||
+ "' (No such file or directory)\n"); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_inner_include_ok) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
BOOST_CHECK_EQUAL( | ||
generate(teng, "<?teng include file=\"page.html\" ?>", *createFragmentTitle(), err), | ||
result_3); | ||
BOOST_CHECK_EQUAL(err.count(), 0); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_inner_include_warning) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
const std::string filename1 = "common-head.html"; | ||
const std::string filename2 = "subdir/paragraph.html"; | ||
|
||
BOOST_CHECK_EQUAL( | ||
generate(teng, "<?teng include file=\"page.html\" ?>", *createFragment(), err), result_4); | ||
BOOST_REQUIRE_EQUAL(err.count(), 2); | ||
BOOST_CHECK_EQUAL(err.getEntries()[0].getLogLine(), | ||
filename1 + "(2,37) Warning: Runtime: Variable '.title' is undefined\n"); | ||
BOOST_CHECK_EQUAL(err.getEntries()[1].getLogLine(), | ||
filename2 + "(1,19) Warning: Runtime: Variable '.title' is undefined\n"); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_include_abs_ok) | ||
{ | ||
Teng::Teng_t teng("templates", 0); | ||
Teng::Error_t err; | ||
|
||
const std::string path = createAbsPath("templates", "subdir/paragraph.html"); | ||
BOOST_REQUIRE(boost::filesystem::exists(path)); | ||
|
||
const std::string templ = "<?teng include file=\"" + path + "\" ?>"; | ||
|
||
BOOST_CHECK_EQUAL(generate(teng, templ, *createFragmentTitle(), err), "Paragraph: Title"); | ||
BOOST_CHECK_EQUAL(err.count(), 0); | ||
} |
Oops, something went wrong.