/*
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&) -> std::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&) -> std::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) -> std::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) -> std::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) -> std::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()
}
}