From 4d9184ef04a3163a4740b2d179398682c9f5140e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 25 Sep 2018 16:29:46 +0200 Subject: Expression breaker. --- test/libdevcore/IterateReplacing.cpp | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/libdevcore/IterateReplacing.cpp (limited to 'test/libdevcore') diff --git a/test/libdevcore/IterateReplacing.cpp b/test/libdevcore/IterateReplacing.cpp new file mode 100644 index 00000000..08cd1e22 --- /dev/null +++ b/test/libdevcore/IterateReplacing.cpp @@ -0,0 +1,97 @@ +/* + 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 iterateReplacing function + */ + +#include + +#include + +using namespace std; + +namespace dev +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(IterateReplacing) + +BOOST_AUTO_TEST_CASE(no_replacement) +{ + vector v{"abc", "def", "ghi"}; + function>(string&)> f = [](string&) -> boost::optional> { return {}; }; + iterateReplacing(v, f); + vector expectation{"abc", "def", "ghi"}; + BOOST_CHECK(v == expectation); +} + +BOOST_AUTO_TEST_CASE(empty_input) +{ + vector v; + function>(string&)> f = [](string&) -> boost::optional> { return {}; }; + iterateReplacing(v, f); + vector expectation; + BOOST_CHECK(v == expectation); +} + +BOOST_AUTO_TEST_CASE(delete_some) +{ + vector v{"abc", "def", "ghi"}; + function>(string&)> f = [](string& _s) -> boost::optional> { + if (_s == "def") + return vector(); + else + return {}; + }; + iterateReplacing(v, f); + vector expectation{"abc", "ghi"}; + BOOST_CHECK(v == expectation); +} + +BOOST_AUTO_TEST_CASE(inject_some_start) +{ + vector v{"abc", "def", "ghi"}; + function>(string&)> f = [](string& _s) -> boost::optional> { + if (_s == "abc") + return vector{"x", "y"}; + else + return {}; + }; + iterateReplacing(v, f); + vector expectation{"x", "y", "def", "ghi"}; + BOOST_CHECK(v == expectation); +} + +BOOST_AUTO_TEST_CASE(inject_some_end) +{ + vector v{"abc", "def", "ghi"}; + function>(string&)> f = [](string& _s) -> boost::optional> { + if (_s == "ghi") + return vector{"x", "y"}; + else + return {}; + }; + iterateReplacing(v, f); + vector expectation{"abc", "def", "x", "y"}; + BOOST_CHECK(v == expectation); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} -- cgit v1.2.3