Allow empty path

just attempt to fetch the root
This commit is contained in:
Mike Bierlee 2022-09-24 17:09:20 +03:00
parent bcd9bf22e3
commit 1272ef1bc4

View file

@ -175,7 +175,7 @@ class ConfigDictionary {
string get(string configPath) { string get(string configPath) {
enforce!ConfigReadException(rootNode !is null, "The config is empty"); enforce!ConfigReadException(rootNode !is null, "The config is empty");
enforce!ConfigReadException(configPath.length > 0, "Supplied config path is empty"); // enforce!ConfigReadException(configPath.length > 0, "Supplied config path is empty");
auto path = new ConfigPath(configPath); auto path = new ConfigPath(configPath);
auto currentNode = rootNode; auto currentNode = rootNode;
@ -278,15 +278,15 @@ version (unittest) {
assertThrown!ConfigReadException(dictionary.get(".")); assertThrown!ConfigReadException(dictionary.get("."));
} }
@("Get value in dictionary with empty path fails") @("Get value in root with empty path")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new ValueNode("hehehe"); dictionary.rootNode = new ValueNode("hehehe");
assertThrown!ConfigReadException(dictionary.get("")); assert(dictionary.get("") == "hehehe");
} }
@("Get value in root") @("Get value in root with just a dot")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new ValueNode("yup"); dictionary.rootNode = new ValueNode("yup");