From 9e7fc124633ae1503ab33f1842f0164d895f46d2 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Tue, 16 Aug 2016 13:25:25 +0000 Subject: Add a ast json converter for InheritanceSpecifier --- test/libsolidity/ASTJSON.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 6d914391..997e0fe8 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -62,6 +62,20 @@ BOOST_AUTO_TEST_CASE(source_location) BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["src"], "13:32:1"); } +BOOST_AUTO_TEST_CASE(inheritance_specifier) +{ + CompilerStack c; + c.addSource("a", "contract C1 {} contract C2 is C1 {}"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + BOOST_CHECK_EQUAL(astJson["children"][1]["attributes"]["name"], "C2"); + BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["name"], "Inheritance"); + BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["name"], "UserDefinedTypeName"); + BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 40ca2c9e977b98083efed96f031c298cf65d0893 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Tue, 16 Aug 2016 14:28:28 +0000 Subject: Add ast json converter for UsingForDirective --- test/libsolidity/ASTJSON.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 997e0fe8..c252b133 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -76,6 +76,23 @@ BOOST_AUTO_TEST_CASE(inheritance_specifier) BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1"); } +BOOST_AUTO_TEST_CASE(using_for_directive) +{ + CompilerStack c; + c.addSource("a", "library L {} contract C { using L for uint; }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value usingFor = astJson["children"][1]["children"][0]; + BOOST_CHECK_EQUAL(usingFor["name"], "UsingFor"); + BOOST_CHECK_EQUAL(usingFor["src"], "26:17:1"); + BOOST_CHECK_EQUAL(usingFor["children"][0]["name"], "UserDefinedTypeName"); + BOOST_CHECK_EQUAL(usingFor["children"][0]["attributes"]["name"], "L"); + BOOST_CHECK_EQUAL(usingFor["children"][1]["name"], "ElementaryTypeName"); + BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From af64219e17f2a01c1a27e19873ab6b03bfd01bfd Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Tue, 16 Aug 2016 14:39:08 +0000 Subject: Check source loctaion in the InhertanceSpecifier test --- test/libsolidity/ASTJSON.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index c252b133..2dcdf0b4 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -72,6 +72,7 @@ BOOST_AUTO_TEST_CASE(inheritance_specifier) Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); BOOST_CHECK_EQUAL(astJson["children"][1]["attributes"]["name"], "C2"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["name"], "Inheritance"); + BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["src"], "30:2:1"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["name"], "UserDefinedTypeName"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1"); } -- cgit v1.2.3 From a9e04217a4f22eb9869a7830ba8f33bd72f2e452 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Tue, 16 Aug 2016 15:18:57 +0000 Subject: Add ast json converter for EnumDefinition --- test/libsolidity/ASTJSON.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 2dcdf0b4..58b17dd8 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -94,6 +94,20 @@ BOOST_AUTO_TEST_CASE(using_for_directive) BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint"); } +BOOST_AUTO_TEST_CASE(enum_definition) +{ + CompilerStack c; + c.addSource("a", "contract C { enum E {} }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value enumDefinition = astJson["children"][0]["children"][0]; + BOOST_CHECK_EQUAL(enumDefinition["name"], "Enum"); + BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E"); + BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 95832da16ea1577dd50e62212dd0ea620e2fcaeb Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Tue, 16 Aug 2016 15:38:24 +0000 Subject: Add ast json converter for EnumValue --- test/libsolidity/ASTJSON.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 58b17dd8..1a9b6981 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -108,6 +108,23 @@ BOOST_AUTO_TEST_CASE(enum_definition) BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1"); } +BOOST_AUTO_TEST_CASE(enum_value) +{ + CompilerStack c; + c.addSource("a", "contract C { enum E { A, B } }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value enumDefinition = astJson["children"][0]["children"][0]; + BOOST_CHECK_EQUAL(enumDefinition["children"][0]["name"], "EnumValue"); + BOOST_CHECK_EQUAL(enumDefinition["children"][0]["attributes"]["name"], "A"); + BOOST_CHECK_EQUAL(enumDefinition["children"][0]["src"], "22:1:1"); + BOOST_CHECK_EQUAL(enumDefinition["children"][1]["name"], "EnumValue"); + BOOST_CHECK_EQUAL(enumDefinition["children"][1]["attributes"]["name"], "B"); + BOOST_CHECK_EQUAL(enumDefinition["children"][1]["src"], "25:1:1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From a5d15e6895212a034f459ba06fe0ca62ba5c0904 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Wed, 17 Aug 2016 14:23:20 +0000 Subject: Add ast json converter for ModifierDefinition --- test/libsolidity/ASTJSON.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 1a9b6981..04733055 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -125,6 +125,20 @@ BOOST_AUTO_TEST_CASE(enum_value) BOOST_CHECK_EQUAL(enumDefinition["children"][1]["src"], "25:1:1"); } +BOOST_AUTO_TEST_CASE(modifier_definition) +{ + CompilerStack c; + c.addSource("a", "contract C { modifier M(uint i) { _ } function F() M(1) {} }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + 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_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From bdc2436ae38b9028311736ef52f36e3525227eb6 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Wed, 17 Aug 2016 14:52:14 +0000 Subject: Add ast json converter for ModifierInvocation and EventDefinition --- test/libsolidity/ASTJSON.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 04733055..69c42814 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -139,6 +139,36 @@ BOOST_AUTO_TEST_CASE(modifier_definition) BOOST_CHECK_EQUAL(modifier["src"], "13:24:1"); } +BOOST_AUTO_TEST_CASE(modifier_invocation) +{ + CompilerStack c; + c.addSource("a", "contract C { modifier M(uint i) { _ } function F() M(1) {} }"); + c.parse(); + map 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"], "Modifier"); + BOOST_CHECK_EQUAL(modifier["src"], "51: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"); +} + +BOOST_AUTO_TEST_CASE(event_definition) +{ + CompilerStack c; + c.addSource("a", "contract C { event E(); }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value event = astJson["children"][0]["children"][0]; + BOOST_CHECK_EQUAL(event["name"], "Event"); + BOOST_CHECK_EQUAL(event["attributes"]["name"], "E"); + BOOST_CHECK_EQUAL(event["src"], "13:10:1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From e9c894c9f80b4a30560c1b88614cbd767abd908b Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Wed, 17 Aug 2016 15:09:21 +0000 Subject: Add ast json converter for ArrayTypeName --- test/libsolidity/ASTJSON.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 69c42814..1a213b23 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -169,6 +169,19 @@ BOOST_AUTO_TEST_CASE(event_definition) BOOST_CHECK_EQUAL(event["src"], "13:10:1"); } +BOOST_AUTO_TEST_CASE(array_type_name) +{ + CompilerStack c; + c.addSource("a", "contract C { uint[] i; }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value array = astJson["children"][0]["children"][0]["children"][0]; + BOOST_CHECK_EQUAL(array["name"], "ArrayTypeName"); + BOOST_CHECK_EQUAL(array["src"], "13:6:1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 406f3a4b5d3827f09e5f1035b79627dcc0e907d9 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Wed, 17 Aug 2016 15:20:17 +0000 Subject: Add ast json converter for PlaceholderStatement --- test/libsolidity/ASTJSON.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 1a213b23..53222f65 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -182,6 +182,19 @@ BOOST_AUTO_TEST_CASE(array_type_name) BOOST_CHECK_EQUAL(array["src"], "13:6:1"); } +BOOST_AUTO_TEST_CASE(placeholder_statement) +{ + CompilerStack c; + c.addSource("a", "contract C { modifier M { _ } }"); + c.parse(); + map sourceIndices; + sourceIndices["a"] = 1; + Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); + Json::Value placeholder = astJson["children"][0]["children"][0]["children"][1]["children"][0]; + BOOST_CHECK_EQUAL(placeholder["name"], "Placeholder"); + BOOST_CHECK_EQUAL(placeholder["src"], "26:1:1"); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3 From 9139d763d302ac2a1afbd9d28c9b0d0861a14d3e Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Thu, 18 Aug 2016 13:12:15 +0000 Subject: Use the full names for JSON AST nodes --- test/libsolidity/ASTJSON.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 53222f65..64624a2d 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -57,8 +57,8 @@ BOOST_AUTO_TEST_CASE(source_location) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); BOOST_CHECK_EQUAL(astJson["name"], "root"); - BOOST_CHECK_EQUAL(astJson["children"][0]["name"], "Contract"); - BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["name"], "Function"); + BOOST_CHECK_EQUAL(astJson["children"][0]["name"], "ContractDefinition"); + BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["name"], "FunctionDefinition"); BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["src"], "13:32:1"); } @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(inheritance_specifier) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); BOOST_CHECK_EQUAL(astJson["children"][1]["attributes"]["name"], "C2"); - BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["name"], "Inheritance"); + BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["name"], "InheritanceSpecifier"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["src"], "30:2:1"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["name"], "UserDefinedTypeName"); BOOST_CHECK_EQUAL(astJson["children"][1]["children"][0]["children"][0]["attributes"]["name"], "C1"); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(using_for_directive) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); Json::Value usingFor = astJson["children"][1]["children"][0]; - BOOST_CHECK_EQUAL(usingFor["name"], "UsingFor"); + BOOST_CHECK_EQUAL(usingFor["name"], "UsingForDirective"); BOOST_CHECK_EQUAL(usingFor["src"], "26:17:1"); BOOST_CHECK_EQUAL(usingFor["children"][0]["name"], "UserDefinedTypeName"); BOOST_CHECK_EQUAL(usingFor["children"][0]["attributes"]["name"], "L"); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(enum_definition) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); Json::Value enumDefinition = astJson["children"][0]["children"][0]; - BOOST_CHECK_EQUAL(enumDefinition["name"], "Enum"); + BOOST_CHECK_EQUAL(enumDefinition["name"], "EnumDefinition"); BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E"); BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1"); } @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(modifier_invocation) 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"], "Modifier"); + BOOST_CHECK_EQUAL(modifier["name"], "ModifierInvocation"); BOOST_CHECK_EQUAL(modifier["src"], "51:4:1"); BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["type"], "modifier (uint256)"); BOOST_CHECK_EQUAL(modifier["children"][0]["attributes"]["value"], "M"); @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(event_definition) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); Json::Value event = astJson["children"][0]["children"][0]; - BOOST_CHECK_EQUAL(event["name"], "Event"); + BOOST_CHECK_EQUAL(event["name"], "EventDefinition"); BOOST_CHECK_EQUAL(event["attributes"]["name"], "E"); BOOST_CHECK_EQUAL(event["src"], "13:10:1"); } @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(placeholder_statement) sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); Json::Value placeholder = astJson["children"][0]["children"][0]["children"][1]["children"][0]; - BOOST_CHECK_EQUAL(placeholder["name"], "Placeholder"); + BOOST_CHECK_EQUAL(placeholder["name"], "PlaceholderStatement"); BOOST_CHECK_EQUAL(placeholder["src"], "26:1:1"); } -- cgit v1.2.3 From 4b9eb299d023989873528e6e52fdc8925d3fcda9 Mon Sep 17 00:00:00 2001 From: Alex Sinyagin Date: Thu, 18 Aug 2016 15:38:20 +0000 Subject: Rename root AST JSON node to SourceUnit --- test/libsolidity/ASTJSON.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index 64624a2d..ec60b668 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) map sourceIndices; sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); - BOOST_CHECK_EQUAL(astJson["name"], "root"); + BOOST_CHECK_EQUAL(astJson["name"], "SourceUnit"); } BOOST_AUTO_TEST_CASE(source_location) @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(source_location) map sourceIndices; sourceIndices["a"] = 1; Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); - BOOST_CHECK_EQUAL(astJson["name"], "root"); + BOOST_CHECK_EQUAL(astJson["name"], "SourceUnit"); BOOST_CHECK_EQUAL(astJson["children"][0]["name"], "ContractDefinition"); BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["name"], "FunctionDefinition"); BOOST_CHECK_EQUAL(astJson["children"][0]["children"][0]["src"], "13:32:1"); -- cgit v1.2.3