aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-15 01:13:25 +0800
committerGitHub <noreply@github.com>2018-08-15 01:13:25 +0800
commit8f27fb1f4a14f369e8feb3ea22a38d50998cad5c (patch)
treeef6d1a3de53c84688c9db123b68836a366a9249d /test
parentcc2dcf5c312bbc8cd7ad5e2b4dfbdb084f77fe03 (diff)
parentf76d4d59197db344613de18d1bfcead34a5e42ba (diff)
downloaddexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.gz
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.bz2
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.lz
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.xz
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.tar.zst
dexon-solidity-8f27fb1f4a14f369e8feb3ea22a38d50998cad5c.zip
Merge pull request #4542 from aarlt/constructor_natspec
Fix: natspec annotations on constructors
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityNatspecJSON.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp
index cc44b578..b97df972 100644
--- a/test/libsolidity/SolidityNatspecJSON.cpp
+++ b/test/libsolidity/SolidityNatspecJSON.cpp
@@ -683,6 +683,131 @@ BOOST_AUTO_TEST_CASE(dev_documenting_no_param_description)
expectNatspecError(sourceCode);
}
+BOOST_AUTO_TEST_CASE(user_constructor)
+{
+ char const *sourceCode = R"(
+ contract test {
+ /// @notice this is a really nice constructor
+ constructor(uint a, uint second) public { }
+ }
+ )";
+
+ char const *natspec = R"ABCDEF({
+ "methods" : {
+ "constructor" : "this is a really nice constructor"
+ }
+ })ABCDEF";
+
+ checkNatspec(sourceCode, "test", natspec, true);
+}
+
+BOOST_AUTO_TEST_CASE(user_constructor_and_function)
+{
+ char const *sourceCode = R"(
+ contract test {
+ /// @notice this is a really nice constructor
+ constructor(uint a, uint second) public { }
+ /// another multiplier
+ function mul(uint a, uint second) public returns(uint d) { return a * 7 + second; }
+ }
+ )";
+
+ char const *natspec = R"ABCDEF({
+ "methods" : {
+ "mul(uint256,uint256)" : {
+ "notice" : "another multiplier"
+ },
+ "constructor" : "this is a really nice constructor"
+ }
+ })ABCDEF";
+
+ checkNatspec(sourceCode, "test", natspec, true);
+}
+
+BOOST_AUTO_TEST_CASE(dev_constructor)
+{
+ char const *sourceCode = R"(
+ contract test {
+ /// @author Alex
+ /// @param a the parameter a is really nice and very useful
+ /// @param second the second parameter is not very useful, it just provides additional confusion
+ constructor(uint a, uint second) public { }
+ }
+ )";
+
+ char const *natspec = R"ABCDEF({
+ "methods" : {
+ "constructor" : {
+ "author" : "Alex",
+ "params" : {
+ "a" : "the parameter a is really nice and very useful",
+ "second" : "the second parameter is not very useful, it just provides additional confusion"
+ }
+ }
+ }
+ })ABCDEF";
+
+ checkNatspec(sourceCode, "test", natspec, false);
+}
+
+BOOST_AUTO_TEST_CASE(dev_constructor_return)
+{
+ char const* sourceCode = R"(
+ contract test {
+ /// @author Alex
+ /// @param a the parameter a is really nice and very useful
+ /// @param second the second parameter is not very useful, it just provides additional confusion
+ /// @return return should not work within constructors
+ constructor(uint a, uint second) public { }
+ }
+ )";
+
+ expectNatspecError(sourceCode);
+}
+
+BOOST_AUTO_TEST_CASE(dev_constructor_and_function)
+{
+ char const *sourceCode = R"(
+ contract test {
+ /// @author Alex
+ /// @param a the parameter a is really nice and very useful
+ /// @param second the second parameter is not very useful, it just provides additional confusion
+ constructor(uint a, uint second) public { }
+ /// @dev Multiplies a number by 7 and adds second parameter
+ /// @param a Documentation for the first parameter starts here.
+ /// Since it's a really complicated parameter we need 2 lines
+ /// @param second Documentation for the second parameter
+ /// @return The result of the multiplication
+ /// and cookies with nutella
+ function mul(uint a, uint second) public returns(uint d) {
+ return a * 7 + second;
+ }
+ }
+ )";
+
+ char const *natspec = R"ABCDEF({
+ "methods" : {
+ "mul(uint256,uint256)" : {
+ "details" : "Multiplies a number by 7 and adds second parameter",
+ "params" : {
+ "a" : "Documentation for the first parameter starts here. Since it's a really complicated parameter we need 2 lines",
+ "second" : "Documentation for the second parameter"
+ },
+ "return" : "The result of the multiplication and cookies with nutella"
+ },
+ "constructor" : {
+ "author" : "Alex",
+ "params" : {
+ "a" : "the parameter a is really nice and very useful",
+ "second" : "the second parameter is not very useful, it just provides additional confusion"
+ }
+ }
+ }
+ })ABCDEF";
+
+ checkNatspec(sourceCode, "test", natspec, false);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}