diff --git a/source/configy/Read.d b/source/configy/Read.d index acc421f..dab72cd 100644 --- a/source/configy/Read.d +++ b/source/configy/Read.d @@ -532,7 +532,7 @@ private TLFR.Type parseMapping (alias TLFR) } } - const enabledState = node.isMappingEnabled!(TLFR.Type)(defaultValue); + const enabledState = node.isMappingEnabled!(TLFR.Type)(path, defaultValue); if (enabledState.field != EnabledState.Field.None) dbgWrite("%s: Mapping is enabled: %s", TLFR.Type.stringof.paint(Cyan), (!!enabledState).paintBool()); @@ -993,7 +993,7 @@ private template NameIs (string searching) /// Returns whether or not the field has a `enabled` / `disabled` field, /// and its value. If it does not, returns `true`. -private EnabledState isMappingEnabled (M) (Node node, auto ref M default_) +private EnabledState isMappingEnabled (M) (Node node, string path, auto ref M default_) { import std.meta : Filter; @@ -1007,13 +1007,13 @@ private EnabledState isMappingEnabled (M) (Node node, auto ref M default_) "` conflicts with `disabled` field `" ~ DMT[0].FieldName ~ "`"); if (auto ptr = "enabled" in node) - return EnabledState(EnabledState.Field.Enabled, (*ptr).as!bool); + return EnabledState(EnabledState.Field.Enabled, (*ptr).parseScalar!(bool)(path, "enabled")); return EnabledState(EnabledState.Field.Enabled, __traits(getMember, default_, EMT[0].FieldName)); } else static if (DMT.length) { if (auto ptr = "disabled" in node) - return EnabledState(EnabledState.Field.Disabled, (*ptr).as!bool); + return EnabledState(EnabledState.Field.Disabled, (*ptr).parseScalar!(bool)(path, "disabled")); return EnabledState(EnabledState.Field.Disabled, __traits(getMember, default_, DMT[0].FieldName)); } else diff --git a/source/configy/Test.d b/source/configy/Test.d index fb6d57e..b3ddde6 100644 --- a/source/configy/Test.d +++ b/source/configy/Test.d @@ -928,3 +928,40 @@ dynamic: assert(c1.static_[1].value == 70); assert(c1.static_[2].value == 71); } + +/// Test around enabled / disabled not being boolean values +unittest +{ + static struct SectionE { + bool enabled; + int value; + string val2; + } + + static struct SectionD { + bool disabled = false; + int value; + string val2; + } + + static struct Config { + SectionE es; + SectionD ds; + } + + try parseConfigString!Config(`es: + enabled: false +ds: + disabled: MAYBE +`, "/dev/null"); + catch (ConfigException exc) + assert(exc.toString() == "/dev/null(3:12): ds.disabled: Expected to be a value of type bool, but is a scalar"); + + try parseConfigString!Config(`es: + enabled: PERHAPS +ds: + disabled: true +`, "/dev/null"); + catch (ConfigException exc) + assert(exc.toString() == "/dev/null(1:11): es.enabled: Expected to be a value of type bool, but is a scalar"); +}