diff options
author | chriseth <c@ethdev.com> | 2015-12-05 10:09:47 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-12-10 02:09:24 +0800 |
commit | 7cb7818ceaf8f2e50cdd66b33a4e0d17c2a0e879 (patch) | |
tree | d6ac5e5fe041afc29dcea2aafa97d60dca82a991 /test | |
parent | e510e7e7929326de3a556d6d2e66b8b4376af7a9 (diff) | |
download | dexon-solidity-7cb7818ceaf8f2e50cdd66b33a4e0d17c2a0e879.tar.gz dexon-solidity-7cb7818ceaf8f2e50cdd66b33a4e0d17c2a0e879.tar.zst dexon-solidity-7cb7818ceaf8f2e50cdd66b33a4e0d17c2a0e879.zip |
Source units are independent scopes.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/Imports.cpp | 83 | ||||
-rw-r--r-- | test/libsolidity/SolidityExpressionCompiler.cpp | 25 |
2 files changed, 99 insertions, 9 deletions
diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp new file mode 100644 index 00000000..b5ff0c54 --- /dev/null +++ b/test/libsolidity/Imports.cpp @@ -0,0 +1,83 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum 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. + + cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. +*/ +/** + * @author Christian <c@ethdev.com> + * @date 2015 + * Tests for high level features like import. + */ + +#include <string> +#include <boost/test/unit_test.hpp> +#include <libsolidity/interface/Exceptions.h> +#include <libsolidity/interface/CompilerStack.h> + +using namespace std; + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +BOOST_AUTO_TEST_SUITE(SolidityImports) + +BOOST_AUTO_TEST_CASE(smoke_test) +{ + CompilerStack c; + c.addSource("a", "contract C {}"); + BOOST_CHECK(c.compile()); +} + +BOOST_AUTO_TEST_CASE(regular_import) +{ + CompilerStack c; + c.addSource("a", "contract C {}"); + c.addSource("b", "import \"a\"; contract D is C {}"); + BOOST_CHECK(c.compile()); +} + +BOOST_AUTO_TEST_CASE(import_does_not_clutter_importee) +{ + CompilerStack c; + c.addSource("a", "contract C { D d; }"); + c.addSource("b", "import \"a\"; contract D is C {}"); + BOOST_CHECK(!c.compile()); +} + +BOOST_AUTO_TEST_CASE(import_is_transitive) +{ + CompilerStack c; + c.addSource("a", "contract C { }"); + c.addSource("b", "import \"a\";"); + c.addSource("c", "import \"b\"; contract D is C {}"); + BOOST_CHECK(c.compile()); +} + +BOOST_AUTO_TEST_CASE(circular_import) +{ + CompilerStack c; + c.addSource("a", "import \"b\"; contract C { D d; }"); + c.addSource("b", "import \"a\"; contract D { C c; }"); + BOOST_CHECK(c.compile()); +} + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} // end namespaces diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index a622c738..0e814e56 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -71,18 +71,21 @@ private: }; Declaration const& resolveDeclaration( - vector<string> const& _namespacedName, NameAndTypeResolver const& _resolver) + SourceUnit const& _sourceUnit, + vector<string> const& _namespacedName, + NameAndTypeResolver const& _resolver +) { - Declaration const* declaration = nullptr; + ASTNode const* scope = &_sourceUnit; // bracers are required, cause msvc couldnt handle this macro in for statement for (string const& namePart: _namespacedName) { - auto declarations = _resolver.resolveName(namePart, declaration); + auto declarations = _resolver.resolveName(namePart, scope); BOOST_REQUIRE(!declarations.empty()); - BOOST_REQUIRE(declaration = *declarations.begin()); + BOOST_REQUIRE(scope = *declarations.begin()); } - BOOST_REQUIRE(declaration); - return *declaration; + BOOST_REQUIRE(scope); + return dynamic_cast<Declaration const&>(*scope); } bytes compileFirstExpression( @@ -140,13 +143,17 @@ bytes compileFirstExpression( unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack context.adjustStackOffset(parametersSize); for (vector<string> const& variable: _localVariables) - context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver)), - parametersSize--); + context.addVariable( + dynamic_cast<VariableDeclaration const&>(resolveDeclaration(*sourceUnit, variable, resolver)), + parametersSize-- + ); ExpressionCompiler(context).compile(*extractor.expression()); for (vector<string> const& function: _functions) - context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); + context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>( + resolveDeclaration(*sourceUnit, function, resolver) + )); bytes instructions = context.assembledObject().bytecode; // debug // cout << eth::disassemble(instructions) << endl; |