From da61930e7f02e26ccc78fc2ae581d6abc8fb33a3 Mon Sep 17 00:00:00 2001 From: Jonathan M Davis Date: Mon, 12 Feb 2018 01:27:13 -0700 Subject: [PATCH] Improve assert messages for invalid EntityTypes. --- source/dxml/dom.d | 18 +++++++++++++++--- source/dxml/parser/package.d | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/source/dxml/dom.d b/source/dxml/dom.d index 8612e0c..5b3789f 100644 --- a/source/dxml/dom.d +++ b/source/dxml/dom.d @@ -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); } @@ -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; } @@ -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); } diff --git a/source/dxml/parser/package.d b/source/dxml/parser/package.d index ccda337..34e3a33 100644 --- a/source/dxml/parser/package.d +++ b/source/dxml/parser/package.d @@ -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)); } @@ -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 @@ -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)); }