aboutsummaryrefslogtreecommitdiffstats
path: root/test/TestCase.cpp
diff options
context:
space:
mode:
authorLazaridis <info@lazaridis.com>2018-11-25 08:02:32 +0800
committerLazaridis <info@lazaridis.com>2018-11-25 08:34:59 +0800
commit56d5dd46687026d2fab80f1b38e8314b080267ab (patch)
treed50e56b15ea54ae7b5968560ff2cfea7a5951d36 /test/TestCase.cpp
parent2e861bf1a0825d17386655cdaaa2c7371b6d2c5c (diff)
downloaddexon-solidity-56d5dd46687026d2fab80f1b38e8314b080267ab.tar.gz
dexon-solidity-56d5dd46687026d2fab80f1b38e8314b080267ab.tar.zst
dexon-solidity-56d5dd46687026d2fab80f1b38e8314b080267ab.zip
decouple TestCase class from test/libsolidity
Diffstat (limited to 'test/TestCase.cpp')
-rw-r--r--test/TestCase.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/TestCase.cpp b/test/TestCase.cpp
new file mode 100644
index 00000000..e9e2c9f2
--- /dev/null
+++ b/test/TestCase.cpp
@@ -0,0 +1,56 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <test/TestCase.h>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+
+#include <stdexcept>
+
+using namespace dev;
+using namespace solidity;
+using namespace dev::solidity::test;
+using namespace std;
+
+bool TestCase::isTestFilename(boost::filesystem::path const& _filename)
+{
+ string extension = _filename.extension().string();
+ return (extension == ".sol" || extension == ".yul") &&
+ !boost::starts_with(_filename.string(), "~") &&
+ !boost::starts_with(_filename.string(), ".");
+}
+
+string TestCase::parseSource(istream& _stream)
+{
+ string source;
+ string line;
+ string const delimiter("// ----");
+ while (getline(_stream, line))
+ if (boost::algorithm::starts_with(line, delimiter))
+ break;
+ else
+ source += line + "\n";
+ return source;
+}
+
+void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c)
+{
+ if (_it == _end || *_it != _c)
+ throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\".");
+ ++_it;
+}