diff options
author | benjaminion <ben@edginet.org> | 2017-07-21 17:23:03 +0800 |
---|---|---|
committer | benjaminion <ben@edginet.org> | 2017-07-21 17:23:03 +0800 |
commit | d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0 (patch) | |
tree | 8e0cfa3e96a84e750d798b32b8f58fac1086cf28 /test | |
parent | d70974ea7caced467c7ce5a7597c66d89e111109 (diff) | |
download | dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar.gz dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar.bz2 dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar.lz dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar.xz dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.tar.zst dexon-solidity-d84e9e7b6a91ddd9cb9462e96883fd681e2a90a0.zip |
LLL: Test cases for nested IF expressions.
Diffstat (limited to 'test')
-rw-r--r-- | test/liblll/EndToEndTest.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp index 4e896fd0..9292d963 100644 --- a/test/liblll/EndToEndTest.cpp +++ b/test/liblll/EndToEndTest.cpp @@ -165,6 +165,56 @@ BOOST_AUTO_TEST_CASE(conditional_seq) BOOST_CHECK(callFallback() == toBigEndian(u256(1))); } +BOOST_AUTO_TEST_CASE(conditional_nested_else) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (< input 0x80) 1 + (if (< input 0xE0) 2 + (if (< input 0xF0) 3 + (if (< input 0xF8) 4 + (if (< input 0xFC) 5 + 6)))))))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + +BOOST_AUTO_TEST_CASE(conditional_nested_then) +{ + char const* sourceCode = R"( + (returnlll + (seq + (def 'input (calldataload 0x04)) + ;; Calculates width in bytes of utf-8 characters. + (return + (if (>= input 0x80) + (if (>= input 0xE0) + (if (>= input 0xF0) + (if (>= input 0xF8) + (if (>= input 0xFC) + 6 5) 4) 3) 2) 1)))) + + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("test()", 0x00) == encodeArgs(u256(1))); + BOOST_CHECK(callContractFunction("test()", 0x80) == encodeArgs(u256(2))); + BOOST_CHECK(callContractFunction("test()", 0xe0) == encodeArgs(u256(3))); + BOOST_CHECK(callContractFunction("test()", 0xf0) == encodeArgs(u256(4))); + BOOST_CHECK(callContractFunction("test()", 0xf8) == encodeArgs(u256(5))); + BOOST_CHECK(callContractFunction("test()", 0xfc) == encodeArgs(u256(6))); +} + BOOST_AUTO_TEST_CASE(exp_operator_const) { char const* sourceCode = R"( |