aboutsummaryrefslogtreecommitdiffstats
path: root/solidityParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'solidityParser.cpp')
-rw-r--r--solidityParser.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/solidityParser.cpp b/solidityParser.cpp
index 6a97a5d9..a9e2d531 100644
--- a/solidityParser.cpp
+++ b/solidityParser.cpp
@@ -21,13 +21,15 @@
*/
#include <string>
-
+#include <memory>
#include <libdevcore/Log.h>
#include <libsolidity/Scanner.h>
#include <libsolidity/Parser.h>
#include <libsolidity/Exceptions.h>
#include <boost/test/unit_test.hpp>
+using namespace std;
+
namespace dev
{
namespace solidity
@@ -40,7 +42,12 @@ namespace
ASTPointer<ContractDefinition> parseText(std::string const& _source)
{
Parser parser;
- return parser.parse(std::make_shared<Scanner>(CharStream(_source)));
+ ASTPointer<SourceUnit> sourceUnit = parser.parse(std::make_shared<Scanner>(CharStream(_source)));
+ for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
+ if (ASTPointer<ContractDefinition> contract = dynamic_pointer_cast<ContractDefinition>(node))
+ return contract;
+ BOOST_FAIL("No contract found in source.");
+ return ASTPointer<ContractDefinition>();
}
}
@@ -380,6 +387,50 @@ BOOST_AUTO_TEST_CASE(statement_starting_with_type_conversion)
BOOST_CHECK_NO_THROW(parseText(text));
}
+BOOST_AUTO_TEST_CASE(import_directive)
+{
+ char const* text = "import \"abc\";\n"
+ "contract test {\n"
+ " function fun() {\n"
+ " uint64(2);\n"
+ " }\n"
+ "}\n";
+ BOOST_CHECK_NO_THROW(parseText(text));
+}
+
+BOOST_AUTO_TEST_CASE(multiple_contracts)
+{
+ char const* text = "contract test {\n"
+ " function fun() {\n"
+ " uint64(2);\n"
+ " }\n"
+ "}\n"
+ "contract test2 {\n"
+ " function fun() {\n"
+ " uint64(2);\n"
+ " }\n"
+ "}\n";
+ BOOST_CHECK_NO_THROW(parseText(text));
+}
+
+BOOST_AUTO_TEST_CASE(multiple_contracts_and_imports)
+{
+ char const* text = "import \"abc\";\n"
+ "contract test {\n"
+ " function fun() {\n"
+ " uint64(2);\n"
+ " }\n"
+ "}\n"
+ "import \"def\";\n"
+ "contract test2 {\n"
+ " function fun() {\n"
+ " uint64(2);\n"
+ " }\n"
+ "}\n"
+ "import \"ghi\";\n";
+ BOOST_CHECK_NO_THROW(parseText(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}