diff options
author | Christian <c@ethdev.com> | 2014-11-06 01:37:27 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2014-11-06 09:46:40 +0800 |
commit | b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126 (patch) | |
tree | dcb03c78f0a064327c35c4e463e760ab83c9186b /solidityEndToEndTest.cpp | |
parent | 4b9dcd95ce5a33440de5014896bfeb99f6436c76 (diff) | |
download | dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar.gz dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar.bz2 dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar.lz dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar.xz dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.tar.zst dexon-solidity-b20e70b4b4357cadcaf4392a2cff7c0e6c6fe126.zip |
Tests for break and continue in nested loops.
Diffstat (limited to 'solidityEndToEndTest.cpp')
-rw-r--r-- | solidityEndToEndTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index b28b8499..7b9e0738 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -151,6 +151,42 @@ BOOST_AUTO_TEST_CASE(while_loop) BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(24))); } +BOOST_AUTO_TEST_CASE(nested_loops) +{ + // tests that break and continue statements in nested loops jump to the correct place + char const* sourceCode = "contract test {\n" + " function f(uint x) returns(uint y) {\n" + " while (x > 1) {\n" + " if (x == 10) break;\n" + " while (x > 5) {\n" + " if (x == 8) break;\n" + " x--;\n" + " if (x == 6) continue;\n" + " return x;\n" + " }\n" + " x--;\n" + " if (x == 3) continue;\n" + " break;\n" + " }\n" + " return x;\n" + " }\n" + "}\n"; + ExecutionFramework framework; + framework.compileAndRun(sourceCode); + BOOST_CHECK(framework.callFunction(0, u256(0)) == toBigEndian(u256(0))); + BOOST_CHECK(framework.callFunction(0, u256(1)) == toBigEndian(u256(1))); + BOOST_CHECK(framework.callFunction(0, u256(2)) == toBigEndian(u256(1))); + BOOST_CHECK(framework.callFunction(0, u256(3)) == toBigEndian(u256(2))); + BOOST_CHECK(framework.callFunction(0, u256(4)) == toBigEndian(u256(2))); + BOOST_CHECK(framework.callFunction(0, u256(5)) == toBigEndian(u256(4))); + BOOST_CHECK(framework.callFunction(0, u256(6)) == toBigEndian(u256(5))); + BOOST_CHECK(framework.callFunction(0, u256(7)) == toBigEndian(u256(5))); + BOOST_CHECK(framework.callFunction(0, u256(8)) == toBigEndian(u256(7))); + BOOST_CHECK(framework.callFunction(0, u256(9)) == toBigEndian(u256(8))); + BOOST_CHECK(framework.callFunction(0, u256(10)) == toBigEndian(u256(10))); + BOOST_CHECK(framework.callFunction(0, u256(11)) == toBigEndian(u256(10))); +} + BOOST_AUTO_TEST_CASE(calling_other_functions) { // note that the index of a function is its index in the sorted sequence of functions |