aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2016-01-19 22:59:39 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:01 +0800
commit51caa04238ce78420e6efc2ce15842effddf3856 (patch)
tree82ed4cec81cb9dd81cbdc3b8134b80fb7e3de780 /test/libsolidity
parent5840a3513f6af498a1dda3aa6670d1f3c6efefb1 (diff)
downloaddexon-solidity-51caa04238ce78420e6efc2ce15842effddf3856.tar.gz
dexon-solidity-51caa04238ce78420e6efc2ce15842effddf3856.tar.zst
dexon-solidity-51caa04238ce78420e6efc2ce15842effddf3856.zip
add more test cases for cond-expr
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0907525b..73e2d662 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -223,6 +223,55 @@ BOOST_AUTO_TEST_CASE(conditional_expression_different_types)
BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(u256(0xcd)));
BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(0xabab)));
}
+
+/* let's add this back when I figure out the correct type conversion.
+BOOST_AUTO_TEST_CASE(conditional_expression_string_literal)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(bool cond) returns (bytes32) {
+ return cond ? "true" : "false";
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(string("true", 4)));
+ BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(string("false", 5)));
+}
+*/
+
+BOOST_AUTO_TEST_CASE(conditional_expression_tuples)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f(bool cond) returns (uint, uint) {
+ return cond ? (1, 2) : (3, 4);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(u256(1), u256(2)));
+ BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(3), u256(4)));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_expression_functions)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function x() returns (uint) { return 1; }
+ function y() returns (uint) { return 2; }
+
+ function f(bool cond) returns (uint) {
+ var z = cond ? x : y;
+ return z();
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(2)));
+}
+
BOOST_AUTO_TEST_CASE(recursive_calls)
{
char const* sourceCode = "contract test {\n"