don't create null anchors (#245)

don't create null anchors
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
This commit is contained in:
Cameron Ross 2019-04-07 05:45:54 -02:30 committed by The Dlang Bot
parent a538662c7e
commit 2e556e4a3a
2 changed files with 79 additions and 1 deletions

View file

@ -113,6 +113,7 @@ struct Event
*/ */
Event event(EventID id)(const Mark start, const Mark end, const string anchor = null) Event event(EventID id)(const Mark start, const Mark end, const string anchor = null)
@safe @safe
in(!(id == EventID.alias_ && anchor == ""), "Missing anchor for alias event")
{ {
Event result; Event result;
result.startMark = start; result.startMark = start;

View file

@ -156,7 +156,7 @@ struct Serializer
return; return;
} }
anchors_[node] = null; anchors_.remove(node);
final switch (node.nodeID) final switch (node.nodeID)
{ {
case NodeID.mapping: case NodeID.mapping:
@ -243,3 +243,80 @@ struct Serializer
} }
} }
} }
// Issue #244
@safe unittest
{
import dyaml.dumper : dumper;
auto node = Node([
Node.Pair(
Node(""),
Node([
Node([
Node.Pair(
Node("d"),
Node([
Node([
Node.Pair(
Node("c"),
Node("")
),
Node.Pair(
Node("b"),
Node("")
),
Node.Pair(
Node(""),
Node("")
)
])
])
),
]),
Node([
Node.Pair(
Node("d"),
Node([
Node(""),
Node(""),
Node([
Node.Pair(
Node("c"),
Node("")
),
Node.Pair(
Node("b"),
Node("")
),
Node.Pair(
Node(""),
Node("")
)
])
])
),
Node.Pair(
Node("z"),
Node("")
),
Node.Pair(
Node(""),
Node("")
)
]),
Node("")
])
),
Node.Pair(
Node("g"),
Node("")
),
Node.Pair(
Node("h"),
Node("")
),
]);
auto stream = appender!string();
dumper().dump(stream, node);
}