aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityParser.cpp
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2015-12-23 00:49:09 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:00 +0800
commitf1d21552fcf9b3f29c9d70b767810da05adeb011 (patch)
treed267b82da94c5866bd6ac5b3d2f13d0e5c66ea9d /test/libsolidity/SolidityParser.cpp
parent7eefa838a3384d3a8a81d73d7e544afa7f3193fc (diff)
downloaddexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar.gz
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar.bz2
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar.lz
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar.xz
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.tar.zst
dexon-solidity-f1d21552fcf9b3f29c9d70b767810da05adeb011.zip
[cond-expr] add parser test cases
Diffstat (limited to 'test/libsolidity/SolidityParser.cpp')
-rw-r--r--test/libsolidity/SolidityParser.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 8e0bf77e..aeaf2baf 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1111,6 +1111,86 @@ BOOST_AUTO_TEST_CASE(inline_array_empty_cells_check_without_lvalue)
BOOST_CHECK(!successParse(text));
}
+BOOST_AUTO_TEST_CASE(conditional_true_false_literal)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint x = true ? 1 : 0;
+ uint y = false ? 0 : 1;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_with_constants)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint x = 3 > 0 ? 3 : 0;
+ uint y = (3 > 0) ? 3 : 0;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_with_variables)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint x = 3;
+ uint y = 1;
+ uint z = (x > y) ? x : y;
+ uint w = x > y ? x : y;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_multiple)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint x = 3 < 0 ? 2 > 1 ? 2 : 1 : 7 > 2 ? 7 : 6;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_with_assignment)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint y = 1;
+ uint x = 3 < 0 ? x = 3 : 6;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_as_left_value)
+{
+ char const* text = R"(
+ contract A {
+ function f() {
+ uint x;
+ uint y;
+ (true ? x : y) = 3;
+ }
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}