diff options
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/ASTJSON.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 34 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 26 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 16 |
4 files changed, 47 insertions, 39 deletions
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index ec60b668..882496d9 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(enum_value) BOOST_AUTO_TEST_CASE(modifier_definition) { CompilerStack c; - c.addSource("a", "contract C { modifier M(uint i) { _ } function F() M(1) {} }"); + c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) {} }"); c.parse(); map<string, unsigned> sourceIndices; sourceIndices["a"] = 1; @@ -136,20 +136,20 @@ BOOST_AUTO_TEST_CASE(modifier_definition) Json::Value modifier = astJson["children"][0]["children"][0]; BOOST_CHECK_EQUAL(modifier["name"], "ModifierDefinition"); BOOST_CHECK_EQUAL(modifier["attributes"]["name"], "M"); - BOOST_CHECK_EQUAL(modifier["src"], "13:24:1"); + BOOST_CHECK_EQUAL(modifier["src"], "13:25:1"); } BOOST_AUTO_TEST_CASE(modifier_invocation) { CompilerStack c; - c.addSource("a", "contract C { modifier M(uint i) { _ } function F() M(1) {} }"); + c.addSource("a", "contract C { modifier M(uint i) { _; } function F() M(1) {} }"); c.parse(); map<string, unsigned> sourceIndices; sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); Json::Value modifier = astJson["children"][0]["children"][1]["children"][2]; BOOST_CHECK_EQUAL(modifier["name"], "ModifierInvocation"); - BOOST_CHECK_EQUAL(modifier["src"], "51:4:1"); + BOOST_CHECK_EQUAL(modifier["src"], "52:4:1"); BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["type"], "modifier (uint256)"); BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["value"], "M"); BOOST_CHECK_EQUAL(modifier["children"][1]["attributes"]["value"], "1"); @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(array_type_name) BOOST_AUTO_TEST_CASE(placeholder_statement) { CompilerStack c; - c.addSource("a", "contract C { modifier M { _ } }"); + c.addSource("a", "contract C { modifier M { _; } }"); c.parse(); map<string, unsigned> sourceIndices; sourceIndices["a"] = 1; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 35b7078d..f3fdef15 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2353,7 +2353,7 @@ BOOST_AUTO_TEST_CASE(function_modifier) char const* sourceCode = R"( contract C { function getOne() nonFree returns (uint r) { return 1; } - modifier nonFree { if (msg.value > 0) _ } + modifier nonFree { if (msg.value > 0) _; } } )"; compileAndRun(sourceCode); @@ -2365,8 +2365,8 @@ BOOST_AUTO_TEST_CASE(function_modifier_local_variables) { char const* sourceCode = R"( contract C { - modifier mod1 { var a = 1; var b = 2; _ } - modifier mod2(bool a) { if (a) return; else _ } + modifier mod1 { var a = 1; var b = 2; _; } + modifier mod2(bool a) { if (a) return; else _; } function f(bool a) mod1 mod2(a) returns (uint r) { return 3; } } )"; @@ -2379,7 +2379,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_loop) { char const* sourceCode = R"( contract C { - modifier repeat(uint count) { for (var i = 0; i < count; ++i) _ } + modifier repeat(uint count) { for (var i = 0; i < count; ++i) _; } function f() repeat(10) returns (uint r) { r += 1; } } )"; @@ -2391,7 +2391,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_invocation) { char const* sourceCode = R"( contract C { - modifier repeat(bool twice) { if (twice) _ _ } + modifier repeat(bool twice) { if (twice) _; _; } function f(bool twice) repeat(twice) returns (uint r) { r += 1; } } )"; @@ -2406,7 +2406,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_multi_with_return) // modifier code block. char const* sourceCode = R"( contract C { - modifier repeat(bool twice) { if (twice) _ _ } + modifier repeat(bool twice) { if (twice) _; _; } function f(bool twice) repeat(twice) returns (uint r) { r += 1; return r; } } )"; @@ -2420,10 +2420,10 @@ BOOST_AUTO_TEST_CASE(function_modifier_overriding) char const* sourceCode = R"( contract A { function f() mod returns (bool r) { return true; } - modifier mod { _ } + modifier mod { _; } } contract C is A { - modifier mod { if (false) _ } + modifier mod { if (false) _; } } )"; compileAndRun(sourceCode); @@ -2439,12 +2439,12 @@ BOOST_AUTO_TEST_CASE(function_modifier_calling_functions_in_creation_context) function f1() mod2 { data |= 0x1; } function f2() { data |= 0x20; } function f3() { } - modifier mod1 { f2(); _ } - modifier mod2 { f3(); if (false) _ } + modifier mod1 { f2(); _; } + modifier mod2 { f3(); if (false) _; } function getData() returns (uint r) { return data; } } contract C is A { - modifier mod1 { f4(); _ } + modifier mod1 { f4(); _; } function f3() { data |= 0x300; } function f4() { data |= 0x4000; } } @@ -2459,11 +2459,11 @@ BOOST_AUTO_TEST_CASE(function_modifier_for_constructor) contract A { uint data; function A() mod1 { data |= 2; } - modifier mod1 { data |= 1; _ } + modifier mod1 { data |= 1; _; } function getData() returns (uint r) { return data; } } contract C is A { - modifier mod1 { data |= 4; _ } + modifier mod1 { data |= 4; _; } } )"; compileAndRun(sourceCode); @@ -6920,7 +6920,7 @@ BOOST_AUTO_TEST_CASE(return_does_not_skip_modifier) contract C { uint public x; modifier setsx { - _ + _; x = 9; } function f() setsx returns (uint) { @@ -6941,7 +6941,7 @@ BOOST_AUTO_TEST_CASE(break_in_modifier) uint public x; modifier run() { for (uint i = 0; i < 10; i++) { - _ + _; break; } } @@ -6963,7 +6963,7 @@ BOOST_AUTO_TEST_CASE(stacked_return_with_modifiers) uint public x; modifier run() { for (uint i = 0; i < 10; i++) { - _ + _; break; } } @@ -6986,7 +6986,7 @@ BOOST_AUTO_TEST_CASE(mutex) modifier protected { if (locked) throw; locked = true; - _ + _; locked = false; } } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 2c126b65..8d4890d1 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -859,8 +859,8 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation) char const* text = R"( contract B { function f() mod1(2, true) mod2("0123456") { } - modifier mod1(uint a, bool b) { if (b) _ } - modifier mod2(bytes7 a) { while (a == "1234567") _ } + modifier mod1(uint a, bool b) { if (b) _; } + modifier mod2(bytes7 a) { while (a == "1234567") _; } } )"; BOOST_CHECK(success(text)); @@ -871,7 +871,7 @@ BOOST_AUTO_TEST_CASE(invalid_function_modifier_type) char const* text = R"( contract B { function f() mod1(true) { } - modifier mod1(uint a) { if (a > 0) _ } + modifier mod1(uint a) { if (a > 0) _; } } )"; BOOST_CHECK(expectError(text) == Error::Type::TypeError); @@ -882,8 +882,8 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_parameters) char const* text = R"( contract B { function f(uint8 a) mod1(a, true) mod2(r) returns (bytes7 r) { } - modifier mod1(uint a, bool b) { if (b) _ } - modifier mod2(bytes7 a) { while (a == "1234567") _ } + modifier mod1(uint a, bool b) { if (b) _; } + modifier mod2(bytes7 a) { while (a == "1234567") _; } } )"; BOOST_CHECK(success(text)); @@ -894,7 +894,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables) char const* text = R"( contract B { function f() mod(x) { uint x = 7; } - modifier mod(uint a) { if (a > 0) _ } + modifier mod(uint a) { if (a > 0) _; } } )"; BOOST_CHECK(success(text)); @@ -903,8 +903,8 @@ BOOST_AUTO_TEST_CASE(function_modifier_invocation_local_variables) BOOST_AUTO_TEST_CASE(legal_modifier_override) { char const* text = R"( - contract A { modifier mod(uint a) { _ } } - contract B is A { modifier mod(uint a) { _ } } + contract A { modifier mod(uint a) { _; } } + contract B is A { modifier mod(uint a) { _; } } )"; BOOST_CHECK(success(text)); } @@ -912,8 +912,8 @@ BOOST_AUTO_TEST_CASE(legal_modifier_override) BOOST_AUTO_TEST_CASE(illegal_modifier_override) { char const* text = R"( - contract A { modifier mod(uint a) { _ } } - contract B is A { modifier mod(uint8 a) { _ } } + contract A { modifier mod(uint a) { _; } } + contract B is A { modifier mod(uint8 a) { _; } } )"; BOOST_CHECK(expectError(text) == Error::Type::TypeError); } @@ -921,7 +921,7 @@ BOOST_AUTO_TEST_CASE(illegal_modifier_override) BOOST_AUTO_TEST_CASE(modifier_overrides_function) { char const* text = R"( - contract A { modifier mod(uint a) { _ } } + contract A { modifier mod(uint a) { _; } } contract B is A { function mod(uint a) { } } )"; BOOST_CHECK(expectError(text) == Error::Type::TypeError); @@ -931,7 +931,7 @@ BOOST_AUTO_TEST_CASE(function_overrides_modifier) { char const* text = R"( contract A { function mod(uint a) { } } - contract B is A { modifier mod(uint a) { _ } } + contract B is A { modifier mod(uint a) { _; } } )"; BOOST_CHECK(expectError(text) == Error::Type::TypeError); } @@ -941,7 +941,7 @@ BOOST_AUTO_TEST_CASE(modifier_returns_value) char const* text = R"( contract A { function f(uint a) mod(2) returns (uint r) { } - modifier mod(uint a) { _ return 7; } + modifier mod(uint a) { _; return 7; } } )"; BOOST_CHECK(expectError(text) == Error::Type::TypeError); diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 92f5a142..0c0e343b 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -681,15 +681,23 @@ BOOST_AUTO_TEST_CASE(placeholder_in_function_context) BOOST_AUTO_TEST_CASE(modifier) { char const* text = "contract c {\n" - " modifier mod { if (msg.sender == 0) _ }\n" + " modifier mod { if (msg.sender == 0) _; }\n" "}\n"; BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(modifier_without_semicolon) +{ + char const* text = "contract c {\n" + " modifier mod { if (msg.sender == 0) _ }\n" + "}\n"; + BOOST_CHECK(!successParse(text)); +} + BOOST_AUTO_TEST_CASE(modifier_arguments) { char const* text = "contract c {\n" - " modifier mod(uint a) { if (msg.sender == a) _ }\n" + " modifier mod(uint a) { if (msg.sender == a) _; }\n" "}\n"; BOOST_CHECK(successParse(text)); } @@ -697,8 +705,8 @@ BOOST_AUTO_TEST_CASE(modifier_arguments) BOOST_AUTO_TEST_CASE(modifier_invocation) { char const* text = "contract c {\n" - " modifier mod1(uint a) { if (msg.sender == a) _ }\n" - " modifier mod2 { if (msg.sender == 2) _ }\n" + " modifier mod1(uint a) { if (msg.sender == a) _; }\n" + " modifier mod2 { if (msg.sender == 2) _; }\n" " function f() mod1(7) mod2 { }\n" "}\n"; BOOST_CHECK(successParse(text)); |