diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-02 00:03:04 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-02 00:03:04 +0800 |
commit | 6b7bec980a482f1e9271b9178d961fbc59a17908 (patch) | |
tree | 4dea4a9eab68ab32c771bf7955afab2118a1b56a /solidityNatspecJSON.cpp | |
parent | 366514a72577d9e9b1c58fc768d084e73ef4f3a5 (diff) | |
download | dexon-solidity-6b7bec980a482f1e9271b9178d961fbc59a17908.tar.gz dexon-solidity-6b7bec980a482f1e9271b9178d961fbc59a17908.tar.zst dexon-solidity-6b7bec980a482f1e9271b9178d961fbc59a17908.zip |
Exporting Natspec documentation to a JSON interface
- Adding a getDocumentation() function to solidity compiler stack
so that we can obtain the natspec interface for a contract
- Adding libjsoncpp as a dependency of libsolidity. This is done
in a dirty way, using libjsonrpc-cpp s an intermediate dependency
for the moment. Will fix soon.
- Start of a test file for Natspec exporting to JSON
Diffstat (limited to 'solidityNatspecJSON.cpp')
-rw-r--r-- | solidityNatspecJSON.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/solidityNatspecJSON.cpp b/solidityNatspecJSON.cpp new file mode 100644 index 00000000..5918eec9 --- /dev/null +++ b/solidityNatspecJSON.cpp @@ -0,0 +1,77 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. + */ +/** + * @author Lefteris Karapetsas <lefteris@ethdev.com> + * @date 2014 + * Unit tests for the solidity compiler JSON Interface output. + */ + +#include <boost/test/unit_test.hpp> +#include <libsolidity/CompilerStack.h> +#include <jsonrpc/json/json.h> + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +class DocumentationChecker +{ +public: + void checkNatspec(std::string const& _code, std::string const& _expectedDocumentationString) + { + m_compilerStack.parse(_code); + auto generatedDocumentationString = m_compilerStack.getDocumentation(); + Json::Value generatedDocumentation; + m_reader.parse(generatedDocumentationString, generatedDocumentation); + Json::Value expectedDocumentation; + m_reader.parse(_expectedDocumentationString, expectedDocumentation); + BOOST_CHECK_MESSAGE(expectedDocumentation == generatedDocumentation, + "Expected " << _expectedDocumentationString << + "\n but got:\n" << generatedDocumentationString); + } + +private: + CompilerStack m_compilerStack; + Json::Reader m_reader; +}; + +BOOST_FIXTURE_TEST_SUITE(SolidityNatspecJSON, DocumentationChecker) + +BOOST_AUTO_TEST_CASE(basic_test) +{ + char const* sourceCode = "contract test {\n" + " /// Multiplies `a` by 7\n" + " function mul(uint a) returns(uint d) { return a * 7; }\n" + "}\n"; + + char const* natspec = "{" + "\"methods\":{" + " \"mul\":{ \"user\": \" Multiplies `a` by 7\"}" + "}}"; + + checkNatspec(sourceCode, natspec); +} + + +BOOST_AUTO_TEST_SUITE_END() + +} +} +} |