mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7881 from ethereum/json-cleanup
Removed non-strict JsonParse helpers
This commit is contained in:
commit
d29a87dfdc
@ -111,16 +111,4 @@ bool jsonParseStrict(string const& _input, Json::Value& _json, string* _errs /*
|
||||
return parse(readerBuilder, _input, _json, _errs);
|
||||
}
|
||||
|
||||
bool jsonParse(string const& _input, Json::Value& _json, string *_errs /* = nullptr */)
|
||||
{
|
||||
static Json::CharReaderBuilder readerBuilder;
|
||||
return parse(readerBuilder, _input, _json, _errs);
|
||||
}
|
||||
|
||||
bool jsonParseFile(string const& _fileName, Json::Value& _json, string *_errs /* = nullptr */)
|
||||
{
|
||||
return jsonParse(readFileAsString(_fileName), _json, _errs);
|
||||
}
|
||||
|
||||
|
||||
} // namespace dev
|
||||
|
@ -41,18 +41,4 @@ std::string jsonCompactPrint(Json::Value const& _input);
|
||||
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
|
||||
bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
|
||||
|
||||
/// Parse a JSON string (@a _input) and writes resulting JSON object to (@a _json)
|
||||
/// \param _input JSON input string
|
||||
/// \param _json [out] resulting JSON object
|
||||
/// \param _errs [out] Formatted error messages
|
||||
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
|
||||
bool jsonParse(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
|
||||
|
||||
/// Parse a JSON string (@a _input) and writes resulting JSON object to (@a _json)
|
||||
/// \param _input file containing JSON input
|
||||
/// \param _json [out] resulting JSON object
|
||||
/// \param _errs [out] Formatted error messages
|
||||
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
|
||||
bool jsonParseFile(std::string const& _fileName, Json::Value& _json, std::string* _errs = nullptr);
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
|
||||
#include <libyul/AsmDataForward.h>
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -69,47 +69,6 @@ BOOST_AUTO_TEST_CASE(json_compact_print)
|
||||
BOOST_CHECK("{\"1\":1,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":2}}" == jsonCompactPrint(json));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_json_not_strict)
|
||||
{
|
||||
Json::Value json;
|
||||
std::string errors;
|
||||
|
||||
// just parse a valid json input
|
||||
BOOST_CHECK(jsonParse("{\"1\":1,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":2}}", json, &errors));
|
||||
BOOST_CHECK(json["1"] == 1);
|
||||
BOOST_CHECK(json["2"] == "2");
|
||||
BOOST_CHECK(json["3"]["3.1"] == "3.1");
|
||||
BOOST_CHECK(json["3"]["3.2"] == 2);
|
||||
|
||||
// trailing garbage is allowed here
|
||||
BOOST_CHECK(jsonParse("{\"1\":2,\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":3}}}}}}}}}}", json, &errors));
|
||||
BOOST_CHECK(json["1"] == 2);
|
||||
BOOST_CHECK(json["2"] == "2");
|
||||
BOOST_CHECK(json["3"]["3.1"] == "3.1");
|
||||
BOOST_CHECK(json["3"]["3.2"] == 3);
|
||||
|
||||
// comments are allowed
|
||||
BOOST_CHECK(jsonParse(
|
||||
"{\"1\":3, // awesome comment\n\"2\":\"2\",\"3\":{\"3.1\":\"3.1\",\"3.2\":4}}", json, &errors
|
||||
));
|
||||
BOOST_CHECK(json["1"] == 3);
|
||||
BOOST_CHECK(json["2"] == "2");
|
||||
BOOST_CHECK(json["3"]["3.1"] == "3.1");
|
||||
BOOST_CHECK(json["3"]["3.2"] == 4);
|
||||
|
||||
// root element other than object or array is allowed
|
||||
BOOST_CHECK(jsonParse("[]", json, &errors));
|
||||
BOOST_CHECK(jsonParse("{}", json, &errors));
|
||||
BOOST_CHECK(jsonParse("1", json, &errors));
|
||||
BOOST_CHECK(json == 1);
|
||||
BOOST_CHECK(jsonParse("\"hello\"", json, &errors));
|
||||
BOOST_CHECK(json == "hello");
|
||||
|
||||
// non-UTF-8 escapes allowed
|
||||
BOOST_CHECK(jsonParse("[ \"\x80\xec\x80\" ]", json, &errors));
|
||||
BOOST_CHECK(json[0] == "\x80\xec\x80");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_json_strict)
|
||||
{
|
||||
Json::Value json;
|
||||
|
@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(metadata_useLiteralContent)
|
||||
BOOST_REQUIRE_MESSAGE(compilerStack.compile(), "Compiling contract failed");
|
||||
string metadata_str = compilerStack.metadata("test");
|
||||
Json::Value metadata;
|
||||
jsonParse(metadata_str, metadata);
|
||||
jsonParseStrict(metadata_str, metadata);
|
||||
BOOST_CHECK(dev::test::isValidMetadata(metadata_str));
|
||||
BOOST_CHECK(metadata.isMember("settings"));
|
||||
if (_literal)
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <test/libsolidity/SMTCheckerJSONTest.h>
|
||||
#include <test/Options.h>
|
||||
#include <libsolidity/interface/StandardCompiler.h>
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libdevcore/JSON.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
@ -43,7 +44,7 @@ SMTCheckerTest::SMTCheckerTest(string const& _filename, langutil::EVMVersion _ev
|
||||
|
||||
string jsonFilename = _filename.substr(0, _filename.size() - 4) + ".json";
|
||||
if (
|
||||
!jsonParseFile(jsonFilename, m_smtResponses) ||
|
||||
!jsonParseStrict(readFileAsString(jsonFilename), m_smtResponses) ||
|
||||
!m_smtResponses.isObject()
|
||||
)
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid JSON file."));
|
||||
@ -158,7 +159,7 @@ Json::Value SMTCheckerTest::buildJson(string const& _extra)
|
||||
sources += "}";
|
||||
string input = "{" + language + ", " + sources + "}";
|
||||
Json::Value source;
|
||||
if (!jsonParse(input, source))
|
||||
if (!jsonParseStrict(input, source))
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Could not build JSON from string: " + input));
|
||||
return source;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user