From 39cf0863e50618db1efd1820408e39a198be3c2f Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Tue, 21 Apr 2015 16:55:12 +0200 Subject: [PATCH] passing more unit tests --- test/data/complex.hpp | 3 +- test/data/lambda/null_string.js | 10 ----- test/data/lambda/partial_view.js | 14 ------- test/data/lambda/partial_whitespace.js | 14 ------- test/data/lambda/simple.js | 8 ---- test/data/null_string.hpp | 6 +++ test/data/{lambda => }/null_string.mustache | 2 - test/data/{lambda => }/null_string.txt | 2 - test/data/partial_view.hpp | 40 +++++++++++++++++++ test/data/{lambda => }/partial_view.mustache | 0 test/data/{lambda => }/partial_view.partial | 0 test/data/{lambda => }/partial_view.txt | 0 test/data/partial_whitespace.hpp | 40 +++++++++++++++++++ .../{lambda => }/partial_whitespace.mustache | 0 .../{lambda => }/partial_whitespace.partial | 0 test/data/{lambda => }/partial_whitespace.txt | 0 test/data/simple.hpp | 34 ++++++++++++++++ test/data/{lambda => }/simple.mustache | 0 test/data/{lambda => }/simple.txt | 0 test/test_main.cpp | 4 ++ 20 files changed, 125 insertions(+), 52 deletions(-) delete mode 100644 test/data/lambda/null_string.js delete mode 100644 test/data/lambda/partial_view.js delete mode 100644 test/data/lambda/partial_whitespace.js delete mode 100644 test/data/lambda/simple.js create mode 100644 test/data/null_string.hpp rename test/data/{lambda => }/null_string.mustache (65%) rename test/data/{lambda => }/null_string.txt (69%) create mode 100644 test/data/partial_view.hpp rename test/data/{lambda => }/partial_view.mustache (100%) rename test/data/{lambda => }/partial_view.partial (100%) rename test/data/{lambda => }/partial_view.txt (100%) create mode 100644 test/data/partial_whitespace.hpp rename test/data/{lambda => }/partial_whitespace.mustache (100%) rename test/data/{lambda => }/partial_whitespace.partial (100%) rename test/data/{lambda => }/partial_whitespace.txt (100%) create mode 100644 test/data/simple.hpp rename test/data/{lambda => }/simple.mustache (100%) rename test/data/{lambda => }/simple.txt (100%) diff --git a/test/data/complex.hpp b/test/data/complex.hpp index 481580d..36926a8 100644 --- a/test/data/complex.hpp +++ b/test/data/complex.hpp @@ -45,8 +45,7 @@ public: { register_methods(this, { {"header", &complex::header}, {"item", &complex::item}, - {"list", &complex::list}, {"empty", &complex::empty} - }); + {"list", &complex::list}, {"empty", &complex::empty}}); } mstch::node header() { diff --git a/test/data/lambda/null_string.js b/test/data/lambda/null_string.js deleted file mode 100644 index 984ee51..0000000 --- a/test/data/lambda/null_string.js +++ /dev/null @@ -1,10 +0,0 @@ -({ - name: "Elise", - glytch: true, - binary: false, - value: null, - undef: undefined, - numeric: function() { - return NaN; - } -}) diff --git a/test/data/lambda/partial_view.js b/test/data/lambda/partial_view.js deleted file mode 100644 index 3ad70d3..0000000 --- a/test/data/lambda/partial_view.js +++ /dev/null @@ -1,14 +0,0 @@ -({ - greeting: function () { - return "Welcome"; - }, - farewell: function () { - return "Fair enough, right?"; - }, - name: "Chris", - value: 10000, - taxed_value: function () { - return this.value - (this.value * 0.4); - }, - in_ca: true -}) diff --git a/test/data/lambda/partial_whitespace.js b/test/data/lambda/partial_whitespace.js deleted file mode 100644 index 3ad70d3..0000000 --- a/test/data/lambda/partial_whitespace.js +++ /dev/null @@ -1,14 +0,0 @@ -({ - greeting: function () { - return "Welcome"; - }, - farewell: function () { - return "Fair enough, right?"; - }, - name: "Chris", - value: 10000, - taxed_value: function () { - return this.value - (this.value * 0.4); - }, - in_ca: true -}) diff --git a/test/data/lambda/simple.js b/test/data/lambda/simple.js deleted file mode 100644 index 1d8d6f4..0000000 --- a/test/data/lambda/simple.js +++ /dev/null @@ -1,8 +0,0 @@ -({ - name: "Chris", - value: 10000, - taxed_value: function () { - return this.value - (this.value * 0.4); - }, - in_ca: true -}) diff --git a/test/data/null_string.hpp b/test/data/null_string.hpp new file mode 100644 index 0000000..619a6f9 --- /dev/null +++ b/test/data/null_string.hpp @@ -0,0 +1,6 @@ +const auto null_string_data = mstch::map{ + {"name", std::string{"Elise"}}, + {"glytch", true}, + {"binary", false}, + {"value", mstch::node{}} +}; diff --git a/test/data/lambda/null_string.mustache b/test/data/null_string.mustache similarity index 65% rename from test/data/lambda/null_string.mustache rename to test/data/null_string.mustache index a6f3300..d087a39 100644 --- a/test/data/lambda/null_string.mustache +++ b/test/data/null_string.mustache @@ -2,5 +2,3 @@ Hello {{name}} glytch {{glytch}} binary {{binary}} value {{value}} -undef {{undef}} -numeric {{numeric}} diff --git a/test/data/lambda/null_string.txt b/test/data/null_string.txt similarity index 69% rename from test/data/lambda/null_string.txt rename to test/data/null_string.txt index bcabe0a..8a0428b 100644 --- a/test/data/lambda/null_string.txt +++ b/test/data/null_string.txt @@ -2,5 +2,3 @@ Hello Elise glytch true binary false value -undef -numeric NaN diff --git a/test/data/partial_view.hpp b/test/data/partial_view.hpp new file mode 100644 index 0000000..fa6d7db --- /dev/null +++ b/test/data/partial_view.hpp @@ -0,0 +1,40 @@ +class partial_view: public mstch::object { +private: + int m_value; +public: + partial_view(): m_value{10000} { + register_methods(this, { + {"greeting", &partial_view::greeting}, + {"farewell", &partial_view::farewell}, + {"name", &partial_view::name}, + {"value", &partial_view::value}, + {"taxed_value", &partial_view::taxed_value}, + {"in_ca", &partial_view::in_ca},}); + } + + mstch::node greeting() { + return std::string{"Welcome"}; + } + + mstch::node farewell() { + return std::string{"Fair enough, right?"}; + } + + mstch::node name() { + return std::string{"Chris"}; + } + + mstch::node value() { + return m_value; + } + + mstch::node taxed_value() { + return static_cast(m_value - (m_value * 0.4)); + } + + mstch::node in_ca() { + return true; + } +}; + +const auto partial_view_data = std::make_shared(); \ No newline at end of file diff --git a/test/data/lambda/partial_view.mustache b/test/data/partial_view.mustache similarity index 100% rename from test/data/lambda/partial_view.mustache rename to test/data/partial_view.mustache diff --git a/test/data/lambda/partial_view.partial b/test/data/partial_view.partial similarity index 100% rename from test/data/lambda/partial_view.partial rename to test/data/partial_view.partial diff --git a/test/data/lambda/partial_view.txt b/test/data/partial_view.txt similarity index 100% rename from test/data/lambda/partial_view.txt rename to test/data/partial_view.txt diff --git a/test/data/partial_whitespace.hpp b/test/data/partial_whitespace.hpp new file mode 100644 index 0000000..a63a20c --- /dev/null +++ b/test/data/partial_whitespace.hpp @@ -0,0 +1,40 @@ +class partial_whitespace: public mstch::object { +private: + int m_value; +public: + partial_whitespace(): m_value{10000} { + register_methods(this, { + {"greeting", &partial_whitespace::greeting}, + {"farewell", &partial_whitespace::farewell}, + {"name", &partial_whitespace::name}, + {"value", &partial_whitespace::value}, + {"taxed_value", &partial_whitespace::taxed_value}, + {"in_ca", &partial_whitespace::in_ca},}); + } + + mstch::node greeting() { + return std::string{"Welcome"}; + } + + mstch::node farewell() { + return std::string{"Fair enough, right?"}; + } + + mstch::node name() { + return std::string{"Chris"}; + } + + mstch::node value() { + return m_value; + } + + mstch::node taxed_value() { + return static_cast(m_value - (m_value * 0.4)); + } + + mstch::node in_ca() { + return true; + } +}; + +const auto partial_whitespace_data = std::make_shared(); \ No newline at end of file diff --git a/test/data/lambda/partial_whitespace.mustache b/test/data/partial_whitespace.mustache similarity index 100% rename from test/data/lambda/partial_whitespace.mustache rename to test/data/partial_whitespace.mustache diff --git a/test/data/lambda/partial_whitespace.partial b/test/data/partial_whitespace.partial similarity index 100% rename from test/data/lambda/partial_whitespace.partial rename to test/data/partial_whitespace.partial diff --git a/test/data/lambda/partial_whitespace.txt b/test/data/partial_whitespace.txt similarity index 100% rename from test/data/lambda/partial_whitespace.txt rename to test/data/partial_whitespace.txt diff --git a/test/data/simple.hpp b/test/data/simple.hpp new file mode 100644 index 0000000..5800732 --- /dev/null +++ b/test/data/simple.hpp @@ -0,0 +1,34 @@ +class simple: public mstch::object { +private: + std::string m_name; + int m_value; + bool m_in_ca; +public: + simple(): + m_name{"Chris"}, + m_value{10000}, + m_in_ca{true} + { + register_methods(this, { + {"name", &simple::name}, {"value", &simple::value}, + {"taxed_value", &simple::taxed_value}, {"in_ca", &simple::in_ca}}); + } + + mstch::node name() { + return m_name; + } + + mstch::node value() { + return m_value; + } + + mstch::node taxed_value() { + return static_cast(m_value - (m_value * 0.4)); + } + + mstch::node in_ca() { + return m_in_ca; + } +}; + +const auto simple_data = std::make_shared(); diff --git a/test/data/lambda/simple.mustache b/test/data/simple.mustache similarity index 100% rename from test/data/lambda/simple.mustache rename to test/data/simple.mustache diff --git a/test/data/lambda/simple.txt b/test/data/simple.txt similarity index 100% rename from test/data/lambda/simple.txt rename to test/data/simple.txt diff --git a/test/test_main.cpp b/test/test_main.cpp index 321e393..4ded83e 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -47,16 +47,20 @@ MSTCH_TEST(nesting) MSTCH_TEST(nesting_same_name) MSTCH_TEST(null_lookup_array) MSTCH_TEST(null_lookup_object) +MSTCH_TEST(null_string) MSTCH_TEST(null_view) MSTCH_PARTIAL_TEST(partial_array) MSTCH_PARTIAL_TEST(partial_array_of_partials) MSTCH_PARTIAL_TEST(partial_array_of_partials_implicit) MSTCH_PARTIAL_TEST(partial_empty) MSTCH_PARTIAL_TEST(partial_template) +MSTCH_PARTIAL_TEST(partial_view) +MSTCH_PARTIAL_TEST(partial_whitespace) MSTCH_TEST(recursion_with_same_names) MSTCH_TEST(reuse_of_enumerables) MSTCH_TEST(section_as_context) //MSTCH_PARTIAL_TEST(section_functions_in_partials) +MSTCH_TEST(simple) MSTCH_TEST(string_as_context) MSTCH_TEST(two_in_a_row) MSTCH_TEST(two_sections)