aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-10-21 21:29:58 +0800
committerGitHub <noreply@github.com>2016-10-21 21:29:58 +0800
commit3e13e59ff96d92f18b972f10f4ef1da1ef249b32 (patch)
treeaeecfbc9d8be123a1f9789b1254d1a3727a53320 /test
parent984b8ac1b58309757380101aad644d3b1b30a2cd (diff)
parent4b7fdaa0bd75775d7a17f809c6ac33def5a6b523 (diff)
downloaddexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar.gz
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar.bz2
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar.lz
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar.xz
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.tar.zst
dexon-solidity-3e13e59ff96d92f18b972f10f4ef1da1ef249b32.zip
Merge pull request #1243 from ethereum/1131
Add enums as inheritable members
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp51
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp32
2 files changed, 83 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0a028a45..16002f9a 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3314,6 +3314,57 @@ BOOST_AUTO_TEST_CASE(using_enums)
BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2));
}
+BOOST_AUTO_TEST_CASE(using_contract_enums_with_explicit_contract_name)
+{
+ char const* sourceCode = R"(
+ contract test {
+ enum Choice { A, B, C }
+ function answer () returns (test.Choice _ret)
+ {
+ _ret = test.Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(using_inherited_enum)
+{
+ char const* sourceCode = R"(
+ contract base {
+ enum Choice { A, B, C }
+ }
+
+ contract test is base {
+ function answer () returns (Choice _ret)
+ {
+ _ret = Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(using_inherited_enum_excplicitly)
+{
+ char const* sourceCode = R"(
+ contract base {
+ enum Choice { A, B, C }
+ }
+
+ contract test is base {
+ function answer () returns (base.Choice _ret)
+ {
+ _ret = base.Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
BOOST_AUTO_TEST_CASE(constructing_enums_from_ints)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2c69f663..74632860 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1439,6 +1439,21 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(enum_invalid_direct_member_access)
+{
+ char const* text = R"(
+ contract test {
+ enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
+ function test()
+ {
+ choices = Sit;
+ }
+ ActionChoices choices;
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::DeclarationError);
+}
+
BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay)
{
char const* text = R"(
@@ -1500,6 +1515,23 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values)
BOOST_CHECK(expectError(text) == Error::Type::DeclarationError);
}
+BOOST_AUTO_TEST_CASE(enum_name_resolution_under_current_contract_name)
+{
+ char const* text = R"(
+ contract A {
+ enum Foo {
+ First,
+ Second
+ }
+
+ function a() {
+ A.Foo;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(private_visibility)
{
char const* sourceCode = R"(