From cfab70fd89e98f9301838682b28b9e400e1b2632 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 11 Feb 2017 21:17:24 +0000 Subject: Add tests for interfaces --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 98 ++++++++++++++++++++++ test/libsolidity/SolidityParser.cpp | 9 ++ 2 files changed, 107 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index fa310434..0861dded 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5327,6 +5327,104 @@ BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants) CHECK_SUCCESS(text); } +BOOST_AUTO_TEST_CASE(interface) +{ + char const* text = R"( + interface I { + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_constructor) +{ + char const* text = R"( + interface I { + function I(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_functions) +{ + char const* text = R"( + interface I { + function(); + function f(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_function_bodies) +{ + char const* text = R"( + interface I { + function f() { + } + } + )"; + CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation"); +} + +BOOST_AUTO_TEST_CASE(interface_events) +{ + char const* text = R"( + interface I { + event E(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_inheritance) +{ + char const* text = R"( + interface A { + } + interface I is A { + } + )"; + CHECK_ERROR(text, TypeError, "Interfaces cannot inherit"); +} + + +BOOST_AUTO_TEST_CASE(interface_structs) +{ + char const* text = R"( + interface I { + struct A { + } + } + )"; + CHECK_ERROR(text, TypeError, "Structs cannot be defined in interfaces"); +} + +BOOST_AUTO_TEST_CASE(interface_variables) +{ + char const* text = R"( + interface I { + uint a; + } + )"; + CHECK_ERROR(text, TypeError, "Variables cannot be defined in interfaces"); +} + +BOOST_AUTO_TEST_CASE(using_interface) +{ + char const* text = R"( + interface I { + function f(); + } + contract C is I { + function f() { + } + } + )"; + success(text); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index ffb4b6f2..6e33aba5 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1493,6 +1493,15 @@ BOOST_AUTO_TEST_CASE(scientific_notation) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(interface) +{ + char const* text = R"( + interface Interface { + function f(); + } + )"; + BOOST_CHECK(successParse(text)); +} BOOST_AUTO_TEST_SUITE_END() -- cgit