[yul-phaser] Move stripWhitespace() from Program tests to Common

This commit is contained in:
Kamil Śliwak 2020-02-15 00:09:43 +01:00
parent 71dcbf9df5
commit 837ea96da7
4 changed files with 29 additions and 7 deletions

View File

@ -19,6 +19,8 @@
#include <libyul/optimiser/Suite.h> #include <libyul/optimiser/Suite.h>
#include <regex>
using namespace std; using namespace std;
using namespace solidity; using namespace solidity;
using namespace solidity::yul; using namespace solidity::yul;
@ -32,3 +34,9 @@ map<string, size_t> phaser::test::enumerateOptmisationSteps()
return stepIndices; return stepIndices;
} }
string phaser::test::stripWhitespace(string const& input)
{
regex whitespaceRegex("\\s+");
return regex_replace(input, whitespaceRegex, "");
}

View File

@ -42,6 +42,11 @@ namespace solidity::phaser::test
/// integers. /// integers.
std::map<std::string, size_t> enumerateOptmisationSteps(); std::map<std::string, size_t> enumerateOptmisationSteps();
// STRING UTILITIES
/// Returns the input string with all the whitespace characters (spaces, line endings, etc.) removed.
std::string stripWhitespace(std::string const& input);
// STATISTICAL UTILITIES // STATISTICAL UTILITIES
/// Calculates the mean value of a series of samples given in a vector. /// Calculates the mean value of a series of samples given in a vector.

View File

@ -51,6 +51,20 @@ BOOST_AUTO_TEST_CASE(enumerateOptimisationSteps_should_assing_indices_to_all_ava
} }
} }
BOOST_AUTO_TEST_CASE(stripWhitespace_should_remove_all_whitespace_characters_from_a_string)
{
BOOST_TEST(stripWhitespace("") == "");
BOOST_TEST(stripWhitespace(" ") == "");
BOOST_TEST(stripWhitespace(" \n\t\v ") == "");
BOOST_TEST(stripWhitespace("abc") == "abc");
BOOST_TEST(stripWhitespace(" abc") == "abc");
BOOST_TEST(stripWhitespace("abc ") == "abc");
BOOST_TEST(stripWhitespace(" a b c ") == "abc");
BOOST_TEST(stripWhitespace(" a b\tc\n") == "abc");
BOOST_TEST(stripWhitespace(" a b \n\n c \n\t\v") == "abc");
}
BOOST_AUTO_TEST_CASE(mean_should_calculate_statistical_mean) BOOST_AUTO_TEST_CASE(mean_should_calculate_statistical_mean)
{ {
BOOST_TEST(mean<int>({0}) == 0.0); BOOST_TEST(mean<int>({0}) == 0.0);

View File

@ -15,6 +15,8 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>. along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <test/yulPhaser/Common.h>
#include <tools/yulPhaser/Exceptions.h> #include <tools/yulPhaser/Exceptions.h>
#include <tools/yulPhaser/Program.h> #include <tools/yulPhaser/Program.h>
@ -30,7 +32,6 @@
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <cassert> #include <cassert>
#include <regex>
#include <string> #include <string>
using namespace std; using namespace std;
@ -51,12 +52,6 @@ namespace
else else
return _block; return _block;
} }
string stripWhitespace(string const& input)
{
regex whitespaceRegex("\\s+");
return regex_replace(input, whitespaceRegex, "");
}
} }
namespace solidity::phaser::test namespace solidity::phaser::test