From b38a107b467152af8af28e435f7506926c321c4a Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 10 Apr 2015 12:56:31 +0200 Subject: [PATCH] unit test refactor --- CMakeLists.txt | 36 ++-- test/data/{falsy_array.h => falsy_array.data} | 4 +- ...ent_context.h => grandparent_context.data} | 4 +- ...icit_iterator.h => implicit_iterator.data} | 4 +- .../{included_tag.h => included_tag.data} | 4 +- test/data/inverted_section.data | 3 + test/data/inverted_section.h | 3 - ...onmarks.h => keys_with_questionmarks.data} | 4 +- test/data/multiline_comment.data | 1 + test/data/multiline_comment.h | 1 - test/data/nested_dot.data | 1 + test/data/nested_dot.h | 1 - ...sted_iterating.h => nested_iterating.data} | 4 +- test/data/{nesting.h => nesting.data} | 4 +- ...ing_same_name.h => nesting_same_name.data} | 4 +- ..._lookup_array.h => null_lookup_array.data} | 4 +- ...ookup_object.h => null_lookup_object.data} | 4 +- test/data/{null_view.h => null_view.data} | 4 +- ...names.h => recursion_with_same_names.data} | 4 +- ...numerables.h => reuse_of_enumerables.data} | 4 +- ...n_as_context.h => section_as_context.data} | 4 +- ...ng_as_context.h => string_as_context.data} | 4 +- .../{two_in_a_row.h => two_in_a_row.data} | 4 +- test/data/two_sections.data | 1 + test/data/two_sections.h | 1 - test/data/{whitespace.h => whitespace.data} | 4 +- test/data/zero_view.data | 1 + test/data/zero_view.h | 1 - test/filetoheader.cpp | 20 +- test/main.cpp | 177 ------------------ test/test_main.cpp | 45 +++++ 31 files changed, 117 insertions(+), 243 deletions(-) rename test/data/{falsy_array.h => falsy_array.data} (89%) rename test/data/{grandparent_context.h => grandparent_context.data} (95%) rename test/data/{implicit_iterator.h => implicit_iterator.data} (81%) rename test/data/{included_tag.h => included_tag.data} (61%) create mode 100644 test/data/inverted_section.data delete mode 100644 test/data/inverted_section.h rename test/data/{keys_with_questionmarks.h => keys_with_questionmarks.data} (69%) create mode 100644 test/data/multiline_comment.data delete mode 100644 test/data/multiline_comment.h create mode 100644 test/data/nested_dot.data delete mode 100644 test/data/nested_dot.h rename test/data/{nested_iterating.h => nested_iterating.data} (84%) rename test/data/{nesting.h => nesting.data} (85%) rename test/data/{nesting_same_name.h => nesting_same_name.data} (81%) rename test/data/{null_lookup_array.h => null_lookup_array.data} (88%) rename test/data/{null_lookup_object.h => null_lookup_object.data} (91%) rename test/data/{null_view.h => null_view.data} (67%) rename test/data/{recursion_with_same_names.h => recursion_with_same_names.data} (88%) rename test/data/{reuse_of_enumerables.h => reuse_of_enumerables.data} (83%) rename test/data/{section_as_context.h => section_as_context.data} (91%) rename test/data/{string_as_context.h => string_as_context.data} (79%) rename test/data/{two_in_a_row.h => two_in_a_row.data} (70%) create mode 100644 test/data/two_sections.data delete mode 100644 test/data/two_sections.h rename test/data/{whitespace.h => whitespace.data} (69%) create mode 100644 test/data/zero_view.data delete mode 100644 test/data/zero_view.h delete mode 100644 test/main.cpp create mode 100644 test/test_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b063e0..1e8437f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,30 +21,32 @@ set(SRC add_library(mstch STATIC ${SRC}) -add_executable(mstch_test test/main.cpp) +add_executable(mstch_test test/test_main.cpp) target_link_libraries(mstch_test mstch) add_executable(filetoheader test/filetoheader.cpp) target_link_libraries(filetoheader ${Boost_PROGRAM_OPTIONS_LIBRARY}) +file(GLOB data_files RELATIVE + "${CMAKE_SOURCE_DIR}/test/data" + "${CMAKE_SOURCE_DIR}/test/data/*.data") + +foreach(data_file ${data_files}) + list(APPEND genargs "-D${data_file}") +endforeach(data_file) + +file(GLOB string_files RELATIVE + "${CMAKE_SOURCE_DIR}/test/data" + "${CMAKE_SOURCE_DIR}/test/data/*.mustache" + "${CMAKE_SOURCE_DIR}/test/data/*.txt") + +foreach(string_file ${string_files}) + list(APPEND genargs "-S${string_file}") +endforeach(string_file) + add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/test_data.h - COMMAND ${CMAKE_BINARY_DIR}/filetoheader --output ${CMAKE_BINARY_DIR}/test_data.h --namespace mstchtest - -Dampersand_escape.data -Sampersand_escape.mustache -Sampersand_escape.txt - -Dapostrophe.data -Sapostrophe.mustache -Sapostrophe.txt - -Darray_of_strings.data -Sarray_of_strings.mustache -Sarray_of_strings.txt - -Dbackslashes.data -Sbackslashes.mustache -Sbackslashes.txt - -Dbug_11_eating_whitespace.data -Sbug_11_eating_whitespace.mustache -Sbug_11_eating_whitespace.txt - -Dbug_length_property.data -Sbug_length_property.mustache -Sbug_length_property.txt - -Dcontext_lookup.data -Scontext_lookup.mustache -Scontext_lookup.txt - -Ddisappearing_whitespace.data -Sdisappearing_whitespace.mustache -Sdisappearing_whitespace.txt - -Ddouble_render.data -Sdouble_render.mustache -Sdouble_render.txt - -Dempty_list.data -Sempty_list.mustache -Sempty_list.txt - -Dempty_sections.data -Sempty_sections.mustache -Sempty_sections.txt - -Dempty_string.data -Sempty_string.mustache -Sempty_string.txt - -Dempty_template.data -Sempty_template.mustache -Sempty_template.txt - -Derror_not_found.data -Serror_not_found.mustache -Serror_not_found.txt - -Dfalsy.data -Sfalsy.mustache -Sfalsy.txt + COMMAND ${CMAKE_BINARY_DIR}/filetoheader --output ${CMAKE_BINARY_DIR}/test_data.h --namespace mstchtest ${genargs} DEPENDS ${CMAKE_BINARY_DIR}/filetoheader WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test/data/) set_source_files_properties(${CMAKE_BINARY_DIR}/test_data.h PROPERTIES GENERATED TRUE) diff --git a/test/data/falsy_array.h b/test/data/falsy_array.data similarity index 89% rename from test/data/falsy_array.h rename to test/data/falsy_array.data index d7b44c4..cd23955 100644 --- a/test/data/falsy_array.h +++ b/test/data/falsy_array.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"list", mstch::array{ mstch::array{std::string{""}, std::string{"emptyString"}}, mstch::array{mstch::array{}, std::string{"emptyArray"}}, mstch::array{0, std::string{"zero"}}, mstch::array{mstch::node{}, std::string{"null"}} }} -}; +} \ No newline at end of file diff --git a/test/data/grandparent_context.h b/test/data/grandparent_context.data similarity index 95% rename from test/data/grandparent_context.h rename to test/data/grandparent_context.data index 01015ed..f43d1fd 100644 --- a/test/data/grandparent_context.h +++ b/test/data/grandparent_context.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"grand_parent_id", std::string{"grand_parent1"}}, {"parent_contexts", mstch::array{ mstch::object{ @@ -16,4 +16,4 @@ auto data = mstch::object{ }} } }} -}; +} \ No newline at end of file diff --git a/test/data/implicit_iterator.h b/test/data/implicit_iterator.data similarity index 81% rename from test/data/implicit_iterator.h rename to test/data/implicit_iterator.data index 8765cd2..543e397 100644 --- a/test/data/implicit_iterator.h +++ b/test/data/implicit_iterator.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"data", mstch::object{ {"author", mstch::object{ {"twitter_id", 819606}, {"name", std::string{"janl"}} }} }} -}; +} diff --git a/test/data/included_tag.h b/test/data/included_tag.data similarity index 61% rename from test/data/included_tag.h rename to test/data/included_tag.data index 1885ed6..18a02cc 100644 --- a/test/data/included_tag.h +++ b/test/data/included_tag.data @@ -1,3 +1,3 @@ -auto data = mstch::object{ +mstch::object{ {"html", std::string{"I like {{mustache}}"}} -}; +} \ No newline at end of file diff --git a/test/data/inverted_section.data b/test/data/inverted_section.data new file mode 100644 index 0000000..cbca8a6 --- /dev/null +++ b/test/data/inverted_section.data @@ -0,0 +1,3 @@ +mstch::object{ + {"repos", mstch::array{}} +} \ No newline at end of file diff --git a/test/data/inverted_section.h b/test/data/inverted_section.h deleted file mode 100644 index c2e4d6a..0000000 --- a/test/data/inverted_section.h +++ /dev/null @@ -1,3 +0,0 @@ -auto data = mstch::object{ - {"repos", mstch::array{}} -}; diff --git a/test/data/keys_with_questionmarks.h b/test/data/keys_with_questionmarks.data similarity index 69% rename from test/data/keys_with_questionmarks.h rename to test/data/keys_with_questionmarks.data index c99c2ac..e9f1612 100644 --- a/test/data/keys_with_questionmarks.h +++ b/test/data/keys_with_questionmarks.data @@ -1,5 +1,5 @@ -auto data = mstch::object{ +mstch::object{ {"person?", mstch::object{ {"name", std::string{"Jon"}} }} -}; +} \ No newline at end of file diff --git a/test/data/multiline_comment.data b/test/data/multiline_comment.data new file mode 100644 index 0000000..2901e22 --- /dev/null +++ b/test/data/multiline_comment.data @@ -0,0 +1 @@ +mstch::object{} \ No newline at end of file diff --git a/test/data/multiline_comment.h b/test/data/multiline_comment.h deleted file mode 100644 index f040324..0000000 --- a/test/data/multiline_comment.h +++ /dev/null @@ -1 +0,0 @@ -auto data = mstch::object{}; diff --git a/test/data/nested_dot.data b/test/data/nested_dot.data new file mode 100644 index 0000000..b2e5079 --- /dev/null +++ b/test/data/nested_dot.data @@ -0,0 +1 @@ +mstch::object{{"name", std::string{"Bruno"}}} \ No newline at end of file diff --git a/test/data/nested_dot.h b/test/data/nested_dot.h deleted file mode 100644 index 3d0ded5..0000000 --- a/test/data/nested_dot.h +++ /dev/null @@ -1 +0,0 @@ -auto data = mstch::object{{"name", std::string{"Bruno"}}}; diff --git a/test/data/nested_iterating.h b/test/data/nested_iterating.data similarity index 84% rename from test/data/nested_iterating.h rename to test/data/nested_iterating.data index d488f5d..23a71de 100644 --- a/test/data/nested_iterating.h +++ b/test/data/nested_iterating.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"inner", mstch::array{mstch::object{ {"foo", std::string{"foo"}}, {"inner", mstch::array{mstch::object{ {"bar", std::string{"bar"}} }}} }}} -}; +} \ No newline at end of file diff --git a/test/data/nesting.h b/test/data/nesting.data similarity index 85% rename from test/data/nesting.h rename to test/data/nesting.data index 1a1e9d1..e6df18e 100644 --- a/test/data/nesting.h +++ b/test/data/nesting.data @@ -1,7 +1,7 @@ -auto data = mstch::object{ +mstch::object{ {"foo", mstch::array{ mstch::object{{"a", mstch::object{{"b", 1}}}}, mstch::object{{"a", mstch::object{{"b", 2}}}}, mstch::object{{"a", mstch::object{{"b", 3}}}} }} -}; +} \ No newline at end of file diff --git a/test/data/nesting_same_name.h b/test/data/nesting_same_name.data similarity index 81% rename from test/data/nesting_same_name.h rename to test/data/nesting_same_name.data index 5a71a12..397bd7f 100644 --- a/test/data/nesting_same_name.h +++ b/test/data/nesting_same_name.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"items", mstch::array{ mstch::object{ {"name", std::string{"name"}}, {"items", mstch::array{1, 2, 3, 4}} } }} -}; +} \ No newline at end of file diff --git a/test/data/null_lookup_array.h b/test/data/null_lookup_array.data similarity index 88% rename from test/data/null_lookup_array.h rename to test/data/null_lookup_array.data index 3f167da..cf725e1 100644 --- a/test/data/null_lookup_array.h +++ b/test/data/null_lookup_array.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"name", std::string{"David"}}, {"twitter", std::string{"@dasilvacontin"}}, {"farray", mstch::array{ mstch::array{std::string{"Flor"}, std::string{"@florrts"}}, mstch::array{std::string{"Miquel"}, mstch::node{}}, }} -}; +} \ No newline at end of file diff --git a/test/data/null_lookup_object.h b/test/data/null_lookup_object.data similarity index 91% rename from test/data/null_lookup_object.h rename to test/data/null_lookup_object.data index ce12fa8..d739965 100644 --- a/test/data/null_lookup_object.h +++ b/test/data/null_lookup_object.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"name", std::string{"David"}}, {"twitter", std::string{"@dasilvacontin"}}, {"fobject", mstch::array{ @@ -11,4 +11,4 @@ auto data = mstch::object{ {"twitter", mstch::node{}} } }} -}; +} diff --git a/test/data/null_view.h b/test/data/null_view.data similarity index 67% rename from test/data/null_view.h rename to test/data/null_view.data index 7b277d7..cd87d4f 100644 --- a/test/data/null_view.h +++ b/test/data/null_view.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"name", std::string{"Joe"}}, {"friends", mstch::node{}} -}; +} diff --git a/test/data/recursion_with_same_names.h b/test/data/recursion_with_same_names.data similarity index 88% rename from test/data/recursion_with_same_names.h rename to test/data/recursion_with_same_names.data index ed07a15..668b001 100644 --- a/test/data/recursion_with_same_names.h +++ b/test/data/recursion_with_same_names.data @@ -1,8 +1,8 @@ -auto data = mstch::object{ +mstch::object{ {"name", std::string{"name"}}, {"description", std::string{"desc"}}, {"terms", mstch::array{ mstch::object{{"name", std::string{"t1"}}, {"index", 0}}, mstch::object{{"name", std::string{"t2"}}, {"index", 1}} }} -}; +} diff --git a/test/data/reuse_of_enumerables.h b/test/data/reuse_of_enumerables.data similarity index 83% rename from test/data/reuse_of_enumerables.h rename to test/data/reuse_of_enumerables.data index 1560f77..de1974a 100644 --- a/test/data/reuse_of_enumerables.h +++ b/test/data/reuse_of_enumerables.data @@ -1,6 +1,6 @@ -auto data = mstch::object{ +mstch::object{ {"terms", mstch::array{ mstch::object{{"name", std::string{"t1"}}, {"index", 0}}, mstch::object{{"name", std::string{"t2"}}, {"index", 1}} }} -}; +} diff --git a/test/data/section_as_context.h b/test/data/section_as_context.data similarity index 91% rename from test/data/section_as_context.h rename to test/data/section_as_context.data index 2955e5e..ec6f3aa 100644 --- a/test/data/section_as_context.h +++ b/test/data/section_as_context.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"a_object", mstch::object{ {"title", std::string{"this is an object"}}, {"description", std::string{"one of its attributes is a list"}}, @@ -7,4 +7,4 @@ auto data = mstch::object{ mstch::object{{"label", std::string{"listitem2"}}} }} }} -}; +} diff --git a/test/data/string_as_context.h b/test/data/string_as_context.data similarity index 79% rename from test/data/string_as_context.h rename to test/data/string_as_context.data index 8c876a0..2b9d8b7 100644 --- a/test/data/string_as_context.h +++ b/test/data/string_as_context.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"a_string", std::string{"aa"}}, {"a_list", mstch::array{std::string{"a"},std::string{"b"},std::string{"c"}}} -}; +} diff --git a/test/data/two_in_a_row.h b/test/data/two_in_a_row.data similarity index 70% rename from test/data/two_in_a_row.h rename to test/data/two_in_a_row.data index d12724a..3e82cb1 100644 --- a/test/data/two_in_a_row.h +++ b/test/data/two_in_a_row.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"name", std::string{"Joe"}}, {"greeting", std::string{"Welcome"}} -}; +} diff --git a/test/data/two_sections.data b/test/data/two_sections.data new file mode 100644 index 0000000..41f946c --- /dev/null +++ b/test/data/two_sections.data @@ -0,0 +1 @@ +mstch::object{} diff --git a/test/data/two_sections.h b/test/data/two_sections.h deleted file mode 100644 index f040324..0000000 --- a/test/data/two_sections.h +++ /dev/null @@ -1 +0,0 @@ -auto data = mstch::object{}; diff --git a/test/data/whitespace.h b/test/data/whitespace.data similarity index 69% rename from test/data/whitespace.h rename to test/data/whitespace.data index 712b220..38e401e 100644 --- a/test/data/whitespace.h +++ b/test/data/whitespace.data @@ -1,4 +1,4 @@ -auto data = mstch::object{ +mstch::object{ {"tag1", std::string{"Hello"}}, {"tag2", std::string{"World"}} -}; +} diff --git a/test/data/zero_view.data b/test/data/zero_view.data new file mode 100644 index 0000000..b871e5e --- /dev/null +++ b/test/data/zero_view.data @@ -0,0 +1 @@ +mstch::object{{"nums", mstch::array{0, 1, 2}}} diff --git a/test/data/zero_view.h b/test/data/zero_view.h deleted file mode 100644 index 45fd810..0000000 --- a/test/data/zero_view.h +++ /dev/null @@ -1 +0,0 @@ -auto data = mstch::object{{"nums", mstch::array{0, 1, 2}}}; diff --git a/test/filetoheader.cpp b/test/filetoheader.cpp index a7da079..9ecb6a3 100644 --- a/test/filetoheader.cpp +++ b/test/filetoheader.cpp @@ -59,16 +59,20 @@ int main(int argc, char* argv[]) { if(vm.count("namespace")) output << "namespace " << vm["namespace"].as() << " {" << std::endl; - for(auto& string_filename: vm["input-string"].as>()) { - std::ifstream input(string_filename, std::ios::in); - wrap_string(input, output, boost::replace_all_copy(string_filename, ".", "_")); - input.close(); + if(vm.count("input-string")) { + for (auto &string_filename: vm["input-string"].as>()) { + std::ifstream input(string_filename, std::ios::in); + wrap_string(input, output, boost::replace_all_copy(string_filename, ".", "_")); + input.close(); + } } - for(auto& data_filename: vm["input-data"].as>()) { - std::ifstream input(data_filename, std::ios::in); - wrap_data(input, output, boost::replace_all_copy(data_filename, ".", "_")); - input.close(); + if(vm.count("input-data")) { + for(auto& data_filename: vm["input-data"].as>()) { + std::ifstream input(data_filename, std::ios::in); + wrap_data(input, output, boost::replace_all_copy(data_filename, ".", "_")); + input.close(); + } } if(vm.count("namespace")) diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 3f405a8..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#define CATCH_CONFIG_MAIN - -#include "catch.hpp" -#include "mstch.h" -#include "test_data.h" - -#define MSTCH_TEST(x,y) TEST_CASE(x) { REQUIRE(y ## _txt == mstch::render(y ## _mustache, y ## _data)); } - -MSTCH_TEST("Ampersand escape", mstchtest::ampersand_escape) -MSTCH_TEST("Apostrophe", mstchtest::apostrophe) -MSTCH_TEST("Array of strings", mstchtest::array_of_strings) -MSTCH_TEST("Backslashes", mstchtest::backslashes) -MSTCH_TEST("Eating whitespace", mstchtest::bug_11_eating_whitespace) -MSTCH_TEST("Length property", mstchtest::bug_length_property) -MSTCH_TEST("Context lookup", mstchtest::context_lookup) -MSTCH_TEST("Disappearing whitespace", mstchtest::disappearing_whitespace) -MSTCH_TEST("Double render", mstchtest::double_render) -MSTCH_TEST("Empty list", mstchtest::empty_list) -MSTCH_TEST("Empty sections", mstchtest::empty_sections) -MSTCH_TEST("Empty string", mstchtest::empty_string) -MSTCH_TEST("Empty template", mstchtest::empty_template) -MSTCH_TEST("Error not found", mstchtest::error_not_found) -MSTCH_TEST("Falsy", mstchtest::falsy) - -/*TEST_CASE("Falsy array") { - #include "data/falsy_array.h" - auto tpl = file_to_string("data/falsy_array.mustache"); - auto exp = file_to_string("data/falsy_array.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -}*/ - -/*TEST_CASE("Grandparent context") { - #include "data/grandparent_context.h" - auto tpl = file_to_string("data/grandparent_context.mustache"); - auto exp = file_to_string("data/grandparent_context.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Implicit iterator") { - #include "data/implicit_iterator.h" - auto tpl = file_to_string("data/implicit_iterator.mustache"); - auto exp = file_to_string("data/implicit_iterator.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Included tag") { - #include "data/included_tag.h" - auto tpl = file_to_string("data/included_tag.mustache"); - auto exp = file_to_string("data/included_tag.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Inverted section") { - #include "data/inverted_section.h" - auto tpl = file_to_string("data/inverted_section.mustache"); - auto exp = file_to_string("data/inverted_section.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Keys with questionmarks") { - #include "data/keys_with_questionmarks.h" - auto tpl = file_to_string("data/keys_with_questionmarks.mustache"); - auto exp = file_to_string("data/keys_with_questionmarks.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Multiline comment") { - #include "data/multiline_comment.h" - auto tpl = file_to_string("data/multiline_comment.mustache"); - auto exp = file_to_string("data/multiline_comment.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Nested dot") { - #include "data/nested_dot.h" - auto tpl = file_to_string("data/nested_dot.mustache"); - auto exp = file_to_string("data/nested_dot.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Nested iterating") { - #include "data/nested_iterating.h" - auto tpl = file_to_string("data/nested_iterating.mustache"); - auto exp = file_to_string("data/nested_iterating.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Nesting") { - #include "data/nesting.h" - auto tpl = file_to_string("data/nesting.mustache"); - auto exp = file_to_string("data/nesting.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Nesting same name") { - #include "data/nesting_same_name.h" - auto tpl = file_to_string("data/nesting_same_name.mustache"); - auto exp = file_to_string("data/nesting_same_name.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Null lookup array") { - #include "data/null_lookup_array.h" - auto tpl = file_to_string("data/null_lookup_array.mustache"); - auto exp = file_to_string("data/null_lookup_array.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Null lookup object") { - #include "data/null_lookup_object.h" - auto tpl = file_to_string("data/null_lookup_object.mustache"); - auto exp = file_to_string("data/null_lookup_object.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Null view") { - #include "data/null_view.h" - auto tpl = file_to_string("data/null_view.mustache"); - auto exp = file_to_string("data/null_view.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Recursion with same names") { - #include "data/recursion_with_same_names.h" - auto tpl = file_to_string("data/recursion_with_same_names.mustache"); - auto exp = file_to_string("data/recursion_with_same_names.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Reuse of enumerables") { - #include "data/reuse_of_enumerables.h" - auto tpl = file_to_string("data/reuse_of_enumerables.mustache"); - auto exp = file_to_string("data/reuse_of_enumerables.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Section as context") { - #include "data/section_as_context.h" - auto tpl = file_to_string("data/section_as_context.mustache"); - auto exp = file_to_string("data/section_as_context.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("String as context") { - #include "data/string_as_context.h" - auto tpl = file_to_string("data/string_as_context.mustache"); - auto exp = file_to_string("data/string_as_context.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Two in a row") { - #include "data/two_in_a_row.h" - auto tpl = file_to_string("data/two_in_a_row.mustache"); - auto exp = file_to_string("data/two_in_a_row.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Two sections") { - #include "data/two_sections.h" - auto tpl = file_to_string("data/two_sections.mustache"); - auto exp = file_to_string("data/two_sections.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Whitespace") { - #include "data/whitespace.h" - auto tpl = file_to_string("data/whitespace.mustache"); - auto exp = file_to_string("data/whitespace.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Zero view") { - #include "data/zero_view.h" - auto tpl = file_to_string("data/zero_view.mustache"); - auto exp = file_to_string("data/zero_view.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -}*/ diff --git a/test/test_main.cpp b/test/test_main.cpp new file mode 100644 index 0000000..c61fcc4 --- /dev/null +++ b/test/test_main.cpp @@ -0,0 +1,45 @@ +#define CATCH_CONFIG_MAIN + +#include "catch.hpp" +#include "mstch.h" +#include "test_data.h" + +#define MSTCH_TEST(x,y) TEST_CASE(x) { REQUIRE(y ## _txt == mstch::render(y ## _mustache, y ## _data)); } + +MSTCH_TEST("Ampersand escape", mstchtest::ampersand_escape) +MSTCH_TEST("Apostrophe", mstchtest::apostrophe) +MSTCH_TEST("Array of strings", mstchtest::array_of_strings) +MSTCH_TEST("Backslashes", mstchtest::backslashes) +MSTCH_TEST("Eating whitespace", mstchtest::bug_11_eating_whitespace) +MSTCH_TEST("Length property", mstchtest::bug_length_property) +MSTCH_TEST("Context lookup", mstchtest::context_lookup) +MSTCH_TEST("Disappearing whitespace", mstchtest::disappearing_whitespace) +MSTCH_TEST("Double render", mstchtest::double_render) +MSTCH_TEST("Empty list", mstchtest::empty_list) +MSTCH_TEST("Empty sections", mstchtest::empty_sections) +MSTCH_TEST("Empty string", mstchtest::empty_string) +MSTCH_TEST("Empty template", mstchtest::empty_template) +MSTCH_TEST("Error not found", mstchtest::error_not_found) +MSTCH_TEST("Falsy", mstchtest::falsy) +//MSTCH_TEST("Falsy array", mstchtest::falsy_array) +MSTCH_TEST("Grandparent context", mstchtest::grandparent_context) +MSTCH_TEST("Implicit iterator", mstchtest::implicit_iterator) +MSTCH_TEST("Included tag", mstchtest::included_tag) +MSTCH_TEST("Inverted section", mstchtest::inverted_section) +MSTCH_TEST("Keys with questionsmarks", mstchtest::keys_with_questionmarks) +MSTCH_TEST("Multiline comment", mstchtest::multiline_comment) +MSTCH_TEST("Nested dot", mstchtest::nested_dot) +MSTCH_TEST("Nested iterating", mstchtest::nested_iterating) +MSTCH_TEST("Nesting", mstchtest::nesting) +MSTCH_TEST("Nesting same name", mstchtest::nesting_same_name) +//MSTCH_TEST("Null lookup array", mstchtest::null_lookup_array) +MSTCH_TEST("Null lookup object", mstchtest::null_lookup_object) +MSTCH_TEST("Null view", mstchtest::null_view) +MSTCH_TEST("Recursion with same names", mstchtest::recursion_with_same_names) +MSTCH_TEST("Reuse of enumerables", mstchtest::reuse_of_enumerables) +MSTCH_TEST("Section as context", mstchtest::section_as_context) +MSTCH_TEST("String as context", mstchtest::string_as_context) +MSTCH_TEST("Two in a row", mstchtest::two_in_a_row) +MSTCH_TEST("Two sections", mstchtest::two_sections) +MSTCH_TEST("Whitespace", mstchtest::whitespace) +//MSTCH_TEST("Zero view", mstchtest::zero_view)