mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 23:12:44 +01:00
Merge pull request #14471 from obsidiansystems/derivation-options-json-test
FIx `DerivationOptions` JSON and clean up unit tests
This commit is contained in:
commit
34c77ffe38
11 changed files with 578 additions and 300 deletions
|
|
@ -59,6 +59,17 @@ auto getInteger(const nlohmann::json & value) -> std::enable_if_t<std::is_signed
|
|||
throw Error("Out of range: JSON value '%s' cannot be casted to %d-bit integer", value.dump(), 8 * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
std::map<std::string, Args...> getMap(const nlohmann::json::object_t & jsonObject, auto && f)
|
||||
{
|
||||
std::map<std::string, Args...> map;
|
||||
|
||||
for (const auto & [key, value] : jsonObject)
|
||||
map.insert_or_assign(key, f(value));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
const nlohmann::json::boolean_t & getBoolean(const nlohmann::json & value);
|
||||
Strings getStringList(const nlohmann::json & value);
|
||||
StringMap getStringMap(const nlohmann::json & value);
|
||||
|
|
|
|||
|
|
@ -91,14 +91,7 @@ Strings getStringList(const nlohmann::json & value)
|
|||
|
||||
StringMap getStringMap(const nlohmann::json & value)
|
||||
{
|
||||
auto & jsonObject = getObject(value);
|
||||
|
||||
StringMap stringMap;
|
||||
|
||||
for (const auto & [key, value] : jsonObject)
|
||||
stringMap[getString(key)] = getString(value);
|
||||
|
||||
return stringMap;
|
||||
return getMap<std::string, std::less<>>(getObject(value), getString);
|
||||
}
|
||||
|
||||
StringSet getStringSet(const nlohmann::json & value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue