[yul-phaser] Common: Add readLinesFromFile()

This commit is contained in:
Kamil Śliwak
2020-03-18 13:30:58 +01:00
parent 5e814acc3c
commit ff99d25bc3
6 changed files with 79 additions and 0 deletions
+1
View File
@@ -158,6 +158,7 @@ set(yul_phaser_sources
# My current workaround is just to include its source files here but this introduces
# unnecessary duplication. Create a library or find a way to reuse the list in both places.
../tools/yulPhaser/AlgorithmRunner.cpp
../tools/yulPhaser/Common.cpp
../tools/yulPhaser/Chromosome.cpp
../tools/yulPhaser/FitnessMetrics.cpp
../tools/yulPhaser/GeneticAlgorithms.cpp
+20
View File
@@ -15,6 +15,8 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#include <test/yulPhaser/TestHelpers.h>
#include <tools/yulPhaser/Common.h>
#include <libsolutil/CommonData.h>
@@ -22,6 +24,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/output_test_stream.hpp>
#include <fstream>
#include <sstream>
#include <string>
@@ -32,6 +35,12 @@ using namespace solidity::util;
namespace solidity::phaser::test
{
class ReadLinesFromFileFixture
{
protected:
TemporaryDirectory m_tempDir;
};
namespace
{
@@ -60,6 +69,17 @@ map<string, TestEnum> const StringToTestEnumMap = invertMap(TestEnumToStringMap)
BOOST_AUTO_TEST_SUITE(Phaser)
BOOST_AUTO_TEST_SUITE(CommonTest)
BOOST_FIXTURE_TEST_CASE(readLinesFromFile_should_return_all_lines_from_a_text_file_as_strings_without_newlines, ReadLinesFromFileFixture)
{
{
ofstream tmpFile(m_tempDir.memberPath("test-file.txt"));
tmpFile << endl << "Line 1" << endl << endl << endl << "Line 2" << endl << "#" << endl << endl;
}
vector<string> lines = readLinesFromFile(m_tempDir.memberPath("test-file.txt"));
BOOST_TEST((lines == vector<string>{"", "Line 1", "", "", "Line 2", "#", ""}));
}
BOOST_AUTO_TEST_CASE(deserializeChoice_should_convert_string_to_enum)
{
istringstream aStream("a");