aboutsummaryrefslogtreecommitdiffstats
path: root/solidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-17 00:35:00 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-17 07:03:30 +0800
commit0050a1a8f93e119ce0d3afc270783b97156a1393 (patch)
tree56734e6b3c0b37b61eb24381f3c5799b10264221 /solidityEndToEndTest.cpp
parent9f5f39300dd601b1f81b7b7258ad0a87b70cd26d (diff)
downloaddexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar.gz
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar.bz2
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar.lz
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar.xz
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.tar.zst
dexon-solidity-0050a1a8f93e119ce0d3afc270783b97156a1393.zip
Solidity: More tests for the ForStatement
Diffstat (limited to 'solidityEndToEndTest.cpp')
-rw-r--r--solidityEndToEndTest.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp
index 32de9af4..ecd3b63a 100644
--- a/solidityEndToEndTest.cpp
+++ b/solidityEndToEndTest.cpp
@@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(for_loop)
" function f(uint n) returns(uint nfac) {\n"
" nfac = 1;\n"
" for (var i = 2; i <= n; i++)\n"
- " nfac *= 1;\n"
+ " nfac *= i;\n"
" }\n"
"}\n";
compileAndRun(sourceCode);
@@ -198,6 +198,58 @@ BOOST_AUTO_TEST_CASE(for_loop)
testSolidityAgainstCppOnRange(0, for_loop_cpp, 0, 5);
}
+BOOST_AUTO_TEST_CASE(for_loop_empty)
+{
+ char const* sourceCode = "contract test {\n"
+ " function f() returns(uint ret) {\n"
+ " ret = 1;\n"
+ " for (;;)\n"
+ " {\n"
+ " ret += 1;\n"
+ " if (ret >= 10) break;\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+
+ auto for_loop_empty_cpp = []() -> u256
+ {
+ u256 ret = 1;
+ for (;;)
+ {
+ ret += 1;
+ if (ret >= 10) break;
+ }
+ return ret;
+ };
+
+ testSolidityAgainstCpp(0, for_loop_empty_cpp);
+}
+
+BOOST_AUTO_TEST_CASE(for_loop_simple_init_expr)
+{
+ char const* sourceCode = "contract test {\n"
+ " function f(uint n) returns(uint nfac) {\n"
+ " nfac = 1;\n"
+ " uint256 i;\n"
+ " for (i = 2; i <= n; i++)\n"
+ " nfac *= i;\n"
+ " }\n"
+ "}\n";
+ compileAndRun(sourceCode);
+
+ auto for_loop_simple_init_expr_cpp = [](u256 const& n) -> u256
+ {
+ u256 nfac = 1;
+ u256 i;
+ for (i = 2; i <= n; i++)
+ nfac *= i;
+ return nfac;
+ };
+
+ testSolidityAgainstCppOnRange(0, for_loop_simple_init_expr_cpp, 0, 5);
+}
+
BOOST_AUTO_TEST_CASE(calling_other_functions)
{
// note that the index of a function is its index in the sorted sequence of functions