From 837ea96da72ec0fd0caf7e43518269e4fab1117c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 15 Feb 2020 00:09:43 +0100 Subject: [PATCH] [yul-phaser] Move stripWhitespace() from Program tests to Common --- test/yulPhaser/Common.cpp | 8 ++++++++ test/yulPhaser/Common.h | 5 +++++ test/yulPhaser/CommonTest.cpp | 14 ++++++++++++++ test/yulPhaser/Program.cpp | 9 ++------- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/test/yulPhaser/Common.cpp b/test/yulPhaser/Common.cpp index 3cef4ff2b..c3653eaec 100644 --- a/test/yulPhaser/Common.cpp +++ b/test/yulPhaser/Common.cpp @@ -19,6 +19,8 @@ #include +#include + using namespace std; using namespace solidity; using namespace solidity::yul; @@ -32,3 +34,9 @@ map phaser::test::enumerateOptmisationSteps() return stepIndices; } + +string phaser::test::stripWhitespace(string const& input) +{ + regex whitespaceRegex("\\s+"); + return regex_replace(input, whitespaceRegex, ""); +} diff --git a/test/yulPhaser/Common.h b/test/yulPhaser/Common.h index a3dd24bce..3dcf63288 100644 --- a/test/yulPhaser/Common.h +++ b/test/yulPhaser/Common.h @@ -42,6 +42,11 @@ namespace solidity::phaser::test /// integers. std::map 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 /// Calculates the mean value of a series of samples given in a vector. diff --git a/test/yulPhaser/CommonTest.cpp b/test/yulPhaser/CommonTest.cpp index d7268c669..cdcba6f53 100644 --- a/test/yulPhaser/CommonTest.cpp +++ b/test/yulPhaser/CommonTest.cpp @@ -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_TEST(mean({0}) == 0.0); diff --git a/test/yulPhaser/Program.cpp b/test/yulPhaser/Program.cpp index 44c2bfa3c..7d9c81cd3 100644 --- a/test/yulPhaser/Program.cpp +++ b/test/yulPhaser/Program.cpp @@ -15,6 +15,8 @@ along with solidity. If not, see . */ +#include + #include #include @@ -30,7 +32,6 @@ #include #include -#include #include using namespace std; @@ -51,12 +52,6 @@ namespace else return _block; } - - string stripWhitespace(string const& input) - { - regex whitespaceRegex("\\s+"); - return regex_replace(input, whitespaceRegex, ""); - } } namespace solidity::phaser::test