diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2016-07-30 15:13:05 +0800 |
---|---|---|
committer | Rhett Aultman <roadriverrail@gmail.com> | 2016-11-10 23:07:25 +0800 |
commit | 4524ad08701939cc22d28494c57dda1cdfba9e10 (patch) | |
tree | 70ff8928bf6a84f50e2ca54d355be81db01e7bcd /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | dc8a5f4ef5505f2aeb017dfa4c9aca77a9fd93aa (diff) | |
download | dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.gz dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.tar.zst dexon-solidity-4524ad08701939cc22d28494c57dda1cdfba9e10.zip |
Add support for do/while loops
This commit adds support for a standard do <statement> while <expr>;
form of statement. While loops were already being supported; supporting
a do/while loop mostly involves reusing code from while loops but putting
the conditional checking last.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8600443d..a1430b02 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -353,6 +353,34 @@ BOOST_AUTO_TEST_CASE(while_loop) testSolidityAgainstCppOnRange("f(uint256)", while_loop_cpp, 0, 5); } + +BOOST_AUTO_TEST_CASE(do_while_loop) +{ + char const* sourceCode = "contract test {\n" + " function f(uint n) returns(uint nfac) {\n" + " nfac = 1;\n" + " var i = 2;\n" + " do { nfac *= i++; } while (i <= n);\n" + " }\n" + "}\n"; + compileAndRun(sourceCode); + + auto do_while_loop_cpp = [](u256 const& n) -> u256 + { + u256 nfac = 1; + u256 i = 2; + do + { + nfac *= i++; + } + while (i <= n); + + return nfac; + }; + + testSolidityAgainstCppOnRange("f(uint256)", do_while_loop_cpp, 0, 5); +} + BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place |