diff options
author | chriseth <chris@ethereum.org> | 2017-09-20 20:45:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 20:45:06 +0800 |
commit | 2adeb26d4396d94b322aeeef98bfb679a7cbce27 (patch) | |
tree | 76cfdaa435756490590c15e4085e637ca4a24964 /test | |
parent | c0b3e5b0785efd1b601cff470d3e3d4a71b2c283 (diff) | |
parent | e14ab959f928c0a058b7b46d6ba4ee30e7ec08b7 (diff) | |
download | dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar.gz dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar.bz2 dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar.lz dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar.xz dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.tar.zst dexon-solidity-2adeb26d4396d94b322aeeef98bfb679a7cbce27.zip |
Merge pull request #2924 from ethereum/inlineasm-assign-multi
Support multiple assignment in inline assembly
Diffstat (limited to 'test')
-rw-r--r-- | test/libjulia/Parser.cpp | 20 | ||||
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 18 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 25 |
3 files changed, 63 insertions, 0 deletions
diff --git a/test/libjulia/Parser.cpp b/test/libjulia/Parser.cpp index 51070370..f8c1aa4d 100644 --- a/test/libjulia/Parser.cpp +++ b/test/libjulia/Parser.cpp @@ -249,6 +249,26 @@ BOOST_AUTO_TEST_CASE(recursion_depth) CHECK_ERROR(input, ParserError, "recursion"); } +BOOST_AUTO_TEST_CASE(multiple_assignment) +{ + CHECK_ERROR("{ let x:u256 function f() -> a:u256, b:u256 {} 123:u256, x := f() }", ParserError, "Label name / variable name must precede \",\" (multiple assignment)."); + CHECK_ERROR("{ let x:u256 function f() -> a:u256, b:u256 {} x, 123:u256 := f() }", ParserError, "Variable name expected in multiple assignemnt."); + + /// NOTE: Travis hiccups if not having a variable + char const* text = R"( + { + function f(a:u256) -> r1:u256, r2:u256 { + r1 := a + r2 := 7:u256 + } + let x:u256 := 9:u256 + let y:u256 := 2:u256 + x, y := f(x) + } + )"; + BOOST_CHECK(successParse(text)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 0debc66d..da3522b4 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -412,7 +412,25 @@ BOOST_AUTO_TEST_CASE(recursion_depth) CHECK_PARSE_ERROR(input, ParserError, "recursion"); } +BOOST_AUTO_TEST_CASE(multiple_assignment) +{ + CHECK_PARSE_ERROR("{ let x function f() -> a, b {} 123, x := f() }", ParserError, "Label name / variable name must precede \",\" (multiple assignment)."); + CHECK_PARSE_ERROR("{ let x function f() -> a, b {} x, 123 := f() }", ParserError, "Variable name expected in multiple assignemnt."); + /// NOTE: Travis hiccups if not having a variable + char const* text = R"( + { + function f(a) -> r1, r2 { + r1 := a + r2 := 7 + } + let x := 9 + let y := 2 + x, y := f(x) + } + )"; + BOOST_CHECK(successParse(text)); +} BOOST_AUTO_TEST_SUITE_END() diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bdac8278..458b64f4 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7867,6 +7867,31 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_call) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1), u256(2), u256(7))); } +BOOST_AUTO_TEST_CASE(inline_assembly_function_call_assignment) +{ + char const* sourceCode = R"( + contract C { + function f() { + assembly { + let a1, b1, c1 + function asmfun(a, b, c) -> x, y, z { + x := a + y := b + z := 7 + } + a1, b1, c1 := asmfun(1, 2, 3) + mstore(0x00, a1) + mstore(0x20, b1) + mstore(0x40, c1) + return(0, 0x60) + } + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1), u256(2), u256(7))); +} + BOOST_AUTO_TEST_CASE(inline_assembly_function_call2) { char const* sourceCode = R"( |