aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-21 18:00:14 +0800
committerGitHub <noreply@github.com>2017-07-21 18:00:14 +0800
commit75b48616be23ab42db5a9c96a8d45bd3b4fc6ad6 (patch)
tree8e0cfa3e96a84e750d798b32b8f58fac1086cf28
parentd70974ea7caced467c7ce5a7597c66d89e111109 (diff)
parentd84e9e7b6a91ddd9cb9462e96883fd681e2a90a0 (diff)
downloaddexon-solidity-75b48616be23ab42db5a9c96a8d45bd3b4fc6ad6.tar.gz
dexon-solidity-75b48616be23ab42db5a9c96a8d45bd3b4fc6ad6.tar.zst
dexon-solidity-75b48616be23ab42db5a9c96a8d45bd3b4fc6ad6.zip
Merge pull request #2616 from benjaminion/lll-nested-conditional-tests
LLL: Test cases for nested IF expressions.
-rw-r--r--test/liblll/EndToEndTest.cpp50
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"(