mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Added new kind of test: check for specific properties of AST
This commit is contained in:
@@ -144,4 +144,19 @@ bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string*
|
||||
return parse(readerBuilder, _input, _json, _errs);
|
||||
}
|
||||
|
||||
std::optional<Json::Value> jsonValueByPath(Json::Value const& _node, std::string_view _jsonPath)
|
||||
{
|
||||
if (!_node.isObject() || _jsonPath.empty())
|
||||
return {};
|
||||
|
||||
std::string memberName = std::string(_jsonPath.substr(0, _jsonPath.find_first_of('.')));
|
||||
if (!_node.isMember(memberName))
|
||||
return {};
|
||||
|
||||
if (memberName == _jsonPath)
|
||||
return _node[memberName];
|
||||
|
||||
return jsonValueByPath(_node[memberName], _jsonPath.substr(memberName.size() + 1));
|
||||
}
|
||||
|
||||
} // namespace solidity::util
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <json/json.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
|
||||
namespace solidity::util
|
||||
{
|
||||
@@ -67,6 +69,13 @@ std::string jsonPrint(Json::Value const& _input, JsonFormat const& _format);
|
||||
/// \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);
|
||||
|
||||
/// Retrieves the value specified by @p _jsonPath by from a series of nested JSON dictionaries.
|
||||
/// @param _jsonPath A dot-separated series of dictionary keys.
|
||||
/// @param _node The node representing the start of the path.
|
||||
/// @returns The value of the last key on the path. @a nullptr if any node on the path descends
|
||||
/// into something that is not a dictionary or the key is not present.
|
||||
std::optional<Json::Value> jsonValueByPath(Json::Value const& _node, std::string_view _jsonPath);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user