From f958463416e88a769d0904ca3da48dac8a9c1c5a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 12 Sep 2017 16:08:15 +0100 Subject: Rename MiniMoustache to Whiskers in tests --- test/libdevcore/MiniMoustache.cpp | 127 -------------------------------------- test/libdevcore/Whiskers.cpp | 127 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 test/libdevcore/MiniMoustache.cpp create mode 100644 test/libdevcore/Whiskers.cpp (limited to 'test/libdevcore') diff --git a/test/libdevcore/MiniMoustache.cpp b/test/libdevcore/MiniMoustache.cpp deleted file mode 100644 index 84149173..00000000 --- a/test/libdevcore/MiniMoustache.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - This file is part of solidity. - - solidity is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - solidity 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with solidity. If not, see . -*/ -/** - * Unit tests for the mini moustache class. - */ - -#include - -#include "../TestHelper.h" - -using namespace std; - -namespace dev -{ -namespace test -{ - -BOOST_AUTO_TEST_SUITE(WhiskersTest) - -BOOST_AUTO_TEST_CASE(no_templates) -{ - string templ = "this text does not contain templates"; - BOOST_CHECK_EQUAL(Whiskers(templ).render(), templ); -} - -BOOST_AUTO_TEST_CASE(basic_replacement) -{ - string templ = "a x -> ."; - string result = Whiskers(templ) - ("b", "BE") - ("c", "CE") - ("d", "DE") - .render(); - BOOST_CHECK_EQUAL(result, "a BE x CE -> DE."); -} - -BOOST_AUTO_TEST_CASE(tag_unavailable) -{ - string templ = ""; - Whiskers m(templ); - BOOST_CHECK_THROW(m.render(), WhiskersError); -} - -BOOST_AUTO_TEST_CASE(complicated_replacement) -{ - string templ = "a x \n >."; - string result = Whiskers(templ) - ("b", "BE") - ("complicated", "COPL") - ("nesPL \n NEST>."); -} - -BOOST_AUTO_TEST_CASE(non_existing_list) -{ - string templ = "a <#b>"; - Whiskers m(templ); - BOOST_CHECK_THROW(m.render(), WhiskersError); -} - -BOOST_AUTO_TEST_CASE(empty_list) -{ - string templ = "a <#b>x"; - string result = Whiskers(templ)("b", vector{}).render(); - BOOST_CHECK_EQUAL(result, "a x"); -} - -BOOST_AUTO_TEST_CASE(list) -{ - string templ = "a<#b>( - )x"; - vector> list(2); - list[0]["g"] = "GE"; - list[0]["h"] = "H"; - list[1]["g"] = "2GE"; - list[1]["h"] = "2H"; - string result = Whiskers(templ)("b", list).render(); - BOOST_CHECK_EQUAL(result, "a( GE - H )( 2GE - 2H )x"); -} - -BOOST_AUTO_TEST_CASE(recursive_list) -{ - // Check that templates resulting from lists are not expanded again - string templ = "a<#b> 13 "; - vector> list(1); - list[0]["g"] = ""; - string result = Whiskers(templ)("x", "X")("b", list).render(); - BOOST_CHECK_EQUAL(result, "a 13 X"); -} - -BOOST_AUTO_TEST_CASE(list_can_access_upper) -{ - string templ = "<#b>()"; - vector> list(2); - Whiskers m(templ); - string result = m("a", "A")("b", list).render(); - BOOST_CHECK_EQUAL(result, "(A)(A)"); -} - -BOOST_AUTO_TEST_CASE(parameter_collision) -{ - string templ = "a <#b>"; - vector> list(1); - list[0]["a"] = "x"; - Whiskers m(templ); - m("a", "X")("b", list); - BOOST_CHECK_THROW(m.render(), WhiskersError); -} - -BOOST_AUTO_TEST_SUITE_END() - -} -} diff --git a/test/libdevcore/Whiskers.cpp b/test/libdevcore/Whiskers.cpp new file mode 100644 index 00000000..84149173 --- /dev/null +++ b/test/libdevcore/Whiskers.cpp @@ -0,0 +1,127 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * Unit tests for the mini moustache class. + */ + +#include + +#include "../TestHelper.h" + +using namespace std; + +namespace dev +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(WhiskersTest) + +BOOST_AUTO_TEST_CASE(no_templates) +{ + string templ = "this text does not contain templates"; + BOOST_CHECK_EQUAL(Whiskers(templ).render(), templ); +} + +BOOST_AUTO_TEST_CASE(basic_replacement) +{ + string templ = "a x -> ."; + string result = Whiskers(templ) + ("b", "BE") + ("c", "CE") + ("d", "DE") + .render(); + BOOST_CHECK_EQUAL(result, "a BE x CE -> DE."); +} + +BOOST_AUTO_TEST_CASE(tag_unavailable) +{ + string templ = ""; + Whiskers m(templ); + BOOST_CHECK_THROW(m.render(), WhiskersError); +} + +BOOST_AUTO_TEST_CASE(complicated_replacement) +{ + string templ = "a x \n >."; + string result = Whiskers(templ) + ("b", "BE") + ("complicated", "COPL") + ("nesPL \n NEST>."); +} + +BOOST_AUTO_TEST_CASE(non_existing_list) +{ + string templ = "a <#b>"; + Whiskers m(templ); + BOOST_CHECK_THROW(m.render(), WhiskersError); +} + +BOOST_AUTO_TEST_CASE(empty_list) +{ + string templ = "a <#b>x"; + string result = Whiskers(templ)("b", vector{}).render(); + BOOST_CHECK_EQUAL(result, "a x"); +} + +BOOST_AUTO_TEST_CASE(list) +{ + string templ = "a<#b>( - )x"; + vector> list(2); + list[0]["g"] = "GE"; + list[0]["h"] = "H"; + list[1]["g"] = "2GE"; + list[1]["h"] = "2H"; + string result = Whiskers(templ)("b", list).render(); + BOOST_CHECK_EQUAL(result, "a( GE - H )( 2GE - 2H )x"); +} + +BOOST_AUTO_TEST_CASE(recursive_list) +{ + // Check that templates resulting from lists are not expanded again + string templ = "a<#b> 13 "; + vector> list(1); + list[0]["g"] = ""; + string result = Whiskers(templ)("x", "X")("b", list).render(); + BOOST_CHECK_EQUAL(result, "a 13 X"); +} + +BOOST_AUTO_TEST_CASE(list_can_access_upper) +{ + string templ = "<#b>()"; + vector> list(2); + Whiskers m(templ); + string result = m("a", "A")("b", list).render(); + BOOST_CHECK_EQUAL(result, "(A)(A)"); +} + +BOOST_AUTO_TEST_CASE(parameter_collision) +{ + string templ = "a <#b>"; + vector> list(1); + list[0]["a"] = "x"; + Whiskers m(templ); + m("a", "X")("b", list); + BOOST_CHECK_THROW(m.render(), WhiskersError); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} -- cgit