Skip to content

Commit

Permalink
Improve assert messages for invalid EntityTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdavis committed Feb 12, 2018
1 parent 6a7f9fb commit da61930
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
18 changes: 15 additions & 3 deletions source/dxml/dom.d
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,11 @@ public:
{
import dxml.internal : checkedSave;
with(EntityType)
assert(only(elementStart, elementEnd, elementEmpty, pi).canFind(_type));
{
import std.format : format;
assert(only(elementStart, elementEnd, elementEmpty, pi).canFind(_type),
format("name cannot be called with %s", _type));
}
return checkedSave(_name);
}

Expand Down Expand Up @@ -483,7 +487,11 @@ public:
@property auto attributes()
{
with(EntityType)
assert(_type == elementStart || _type == elementEmpty);
{
import std.format : format;
assert(_type == elementStart || _type == elementEmpty,
format("attributes cannot be called with %s", _type));
}
return _attributes;
}

Expand Down Expand Up @@ -572,7 +580,11 @@ public:
{
import dxml.internal : checkedSave;
with(EntityType)
assert(only(cdata, comment, pi, text).canFind(_type));
{
import std.format : format;
assert(only(cdata, comment, pi, text).canFind(_type),
format("text cannot be called with %s", _type));
}
return checkedSave(_text);
}

Expand Down
18 changes: 15 additions & 3 deletions source/dxml/parser/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,11 @@ public:
{
import dxml.internal : checkedSave, stripBCU;
with(EntityType)
assert(only(elementStart, elementEnd, elementEmpty, pi).canFind(_type));
{
import std.format : format;
assert(only(elementStart, elementEnd, elementEmpty, pi).canFind(_type),
format("name cannot be called with %s", _type));
}
return stripBCU!R(checkedSave(_name));
}

Expand Down Expand Up @@ -944,7 +948,11 @@ public:
@property auto attributes()
{
with(EntityType)
assert(_type == elementStart || _type == elementEmpty);
{
import std.format : format;
assert(_type == elementStart || _type == elementEmpty,
format("attributes cannot be called with %s", _type));
}

// STag ::= '<' Name (S Attribute)* S? '>'
// Attribute ::= Name Eq AttValue
Expand Down Expand Up @@ -1244,7 +1252,11 @@ public:
{
import dxml.internal : checkedSave, stripBCU;
with(EntityType)
assert(only(cdata, comment, pi, text).canFind(_type));
{
import std.format : format;
assert(only(cdata, comment, pi, text).canFind(_type),
format("text cannot be called with %s", _type));
}
return stripBCU!R(checkedSave(_savedText.input));
}

Expand Down

0 comments on commit da61930

Please sign in to comment.