From 3ad6d09b82f9b3c4118b3264b1a013384c81e3c2 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 9 Apr 2015 11:33:34 +0200 Subject: added test for empty explicit fields, which currently fails. --- src/core/parser/ParserScope.cpp | 4 ++-- src/core/parser/stack/DocumentHandler.cpp | 1 - test/formats/osxml/OsxmlParserTest.cpp | 17 +++++++++++++++++ testdata/osxmlparser/empty_named_field.osxml | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 testdata/osxmlparser/empty_named_field.osxml diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index c46dc51..e5bf6f6 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -174,12 +174,12 @@ ParserScope::ParserScope() : topLevelDepth(0) {} bool ParserScope::checkUnwound(Logger &logger) const { - if (nodes.size() != topLevelDepth) { + if (nodes.size() > topLevelDepth) { logger.error("Not all open elements have been closed!", SourceLocation{}, MessageMode::NO_CONTEXT); logger.note("Still open elements are: ", SourceLocation{}, MessageMode::NO_CONTEXT); - for (size_t i = topLevelDepth + 1; i < nodes.size(); i++) { + for (size_t i = topLevelDepth; i < nodes.size(); i++) { logger.note(std::string("Element of interal type ") + nodes[i]->type()->name + std::string(" defined here:"), diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index 3e85f72..ce6267f 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -334,7 +334,6 @@ bool DocumentChildHandler::startCommand(Variant::mapType &args) } // Otherwise create a new StructuredEntity - // TODO: Consider Anchors and AnnotationEntities Rooted strct = scope().resolve( Utils::split(name(), ':'), logger()); if (strct == nullptr) { diff --git a/test/formats/osxml/OsxmlParserTest.cpp b/test/formats/osxml/OsxmlParserTest.cpp index 603d6c1..7c7f2a8 100644 --- a/test/formats/osxml/OsxmlParserTest.cpp +++ b/test/formats/osxml/OsxmlParserTest.cpp @@ -384,5 +384,22 @@ TEST(OsxmlParser, documentParsing) } } +TEST(OsxmlParser, emptyNamedField){ + logger.reset(); + XmlStandaloneEnvironment env(logger); + Rooted book_document_node = + env.parse("empty_named_field.osxml", "", "", RttiSet{&RttiTypes::Document}); + ASSERT_FALSE(logger.hasError()); + ASSERT_FALSE(book_document_node == nullptr); + ASSERT_TRUE(book_document_node->isa(&RttiTypes::Document)); + // check the document content. + Rooted doc = book_document_node.cast(); + ASSERT_TRUE(doc->validate(logger)); + checkStructuredEntity(doc->getRoot(), doc, doc, "a"); + ASSERT_EQ(2U, doc->getRoot()->getDescriptor()->getFieldDescriptors().size()); + ASSERT_TRUE(doc->getRoot()->getField(0).empty()); + ASSERT_TRUE(doc->getRoot()->getField(1).empty()); +} + } diff --git a/testdata/osxmlparser/empty_named_field.osxml b/testdata/osxmlparser/empty_named_field.osxml new file mode 100644 index 0000000..2f465ba --- /dev/null +++ b/testdata/osxmlparser/empty_named_field.osxml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + -- cgit v1.2.3