Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of pointers #63

Open
wants to merge 2 commits into
base: v2.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/configy/read.d
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,11 @@ package FR.Type parseField (alias FR)
);
}
}
else static if (is(FR.Type == T*, T))
{
// Allocate and parse pointers' values.
return [node.parseField!(NestedFieldRef!(T, FR))(path, T.init, ctx)].ptr;
}
else
{
static assert (!is(FR.Type == union),
Expand Down
18 changes: 18 additions & 0 deletions source/configy/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -965,3 +965,21 @@ ds:
catch (ConfigException exc)
assert(exc.toString() == "/dev/null(1:11): es.enabled: Expected to be a value of type bool, but is a scalar");
}

/// Test pointers
unittest
{
static struct N {
@Optional int value;
@Optional const N* left, right;
}
auto c = parseConfigString!N(`left:
left:
value: 1
right:
value: 2
`, "/dev/null");
assert(c.left.left.value == 1);
assert(c.left.right is null);
assert(c.right.value == 2);
}
Loading