diff options
author | chriseth <chris@ethereum.org> | 2017-02-15 22:41:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-15 22:41:45 +0800 |
commit | ad751bd3e6f22fadc01d43610ec2e2e008c32f11 (patch) | |
tree | 12a9fe2556bd87a0d7e2695db724d65434f40f42 /test/libsolidity | |
parent | 4189ff5b68f119878807104ebac0137171c8ecd6 (diff) | |
parent | 5e8a1e0ae6dcd269258fe4239060bcc890abacb5 (diff) | |
download | dexon-solidity-ad751bd3e6f22fadc01d43610ec2e2e008c32f11.tar.gz dexon-solidity-ad751bd3e6f22fadc01d43610ec2e2e008c32f11.tar.zst dexon-solidity-ad751bd3e6f22fadc01d43610ec2e2e008c32f11.zip |
Merge pull request #1674 from ethereum/assemblyPrinter
Assembly printer.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 37d17495..8744d96f 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -73,11 +73,22 @@ bool successAssemble(string const& _source, bool _allowWarnings = true) return successParse(_source, true, _allowWarnings); } +void parsePrintCompare(string const& _source) +{ + assembly::InlineAssemblyStack stack; + BOOST_REQUIRE(stack.parse(std::make_shared<Scanner>(CharStream(_source)))); + BOOST_REQUIRE(stack.errors().empty()); + BOOST_CHECK_EQUAL(stack.toString(), _source); +} + } BOOST_AUTO_TEST_SUITE(SolidityInlineAssembly) + +BOOST_AUTO_TEST_SUITE(Parsing) + BOOST_AUTO_TEST_CASE(smoke_test) { BOOST_CHECK(successParse("{ }")); @@ -148,6 +159,60 @@ BOOST_AUTO_TEST_CASE(blocks) BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }")); } +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Printing) + +BOOST_AUTO_TEST_CASE(print_smoke) +{ + parsePrintCompare("{\n}"); +} + +BOOST_AUTO_TEST_CASE(print_instructions) +{ + parsePrintCompare("{\n 7\n 8\n mul\n dup10\n add\n}"); +} + +BOOST_AUTO_TEST_CASE(print_subblock) +{ + parsePrintCompare("{\n {\n dup4\n add\n }\n}"); +} + +BOOST_AUTO_TEST_CASE(print_functional) +{ + parsePrintCompare("{\n mul(sload(0x12), 7)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_label) +{ + parsePrintCompare("{\n loop:\n jump(loop)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_assignments) +{ + parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}"); +} + +BOOST_AUTO_TEST_CASE(print_string_literals) +{ + parsePrintCompare("{\n \"\\n'\\xab\\x95\\\"\"\n}"); +} + +BOOST_AUTO_TEST_CASE(print_string_literal_unicode) +{ + string source = "{ \"\\u1bac\" }"; + string parsed = "{\n \"\\xe1\\xae\\xac\"\n}"; + assembly::InlineAssemblyStack stack; + BOOST_REQUIRE(stack.parse(std::make_shared<Scanner>(CharStream(source)))); + BOOST_REQUIRE(stack.errors().empty()); + BOOST_CHECK_EQUAL(stack.toString(), parsed); + parsePrintCompare(parsed); +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(Analysis) + BOOST_AUTO_TEST_CASE(string_literals) { BOOST_CHECK(successAssemble("{ let x := \"12345678901234567890123456789012\" }")); @@ -212,6 +277,8 @@ BOOST_AUTO_TEST_CASE(revert) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE_END() + } } } // end namespaces |