From 493acd119d730207524cd69fa25868c978bdf0f9 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 18 Feb 2015 10:45:40 +0100 Subject: Added test for bug with structs that do not posses a field --- testdata/osmlparser/struct_with_no_field.osml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 testdata/osmlparser/struct_with_no_field.osml (limited to 'testdata') diff --git a/testdata/osmlparser/struct_with_no_field.osml b/testdata/osmlparser/struct_with_no_field.osml new file mode 100644 index 0000000..8cf2d02 --- /dev/null +++ b/testdata/osmlparser/struct_with_no_field.osml @@ -0,0 +1,12 @@ +\document + +\domain#test + \struct#a[isRoot=true] + \field + \childRef[ref=b] + \struct#b + +\a + \b + \b + -- cgit v1.2.3 From 2de08643afdb4771ef8d1f6dd836ded20db244cf Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 18 Feb 2015 11:32:23 +0100 Subject: Fix for issue #85 -- only allowing explicit fields if no structure elements or data have been given beforehand. Added unit tests. --- src/core/parser/ParserScope.hpp | 9 ++++- src/core/parser/stack/DocumentHandler.cpp | 47 ++++++++++++++++++++---- test/formats/osml/OsmlParserTest.cpp | 27 ++++++++++++++ testdata/osmlparser/explicit_fields.osml | 16 ++++++++ testdata/osmlparser/invalid_explicit_fields.osml | 16 ++++++++ 5 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 testdata/osmlparser/explicit_fields.osml create mode 100644 testdata/osmlparser/invalid_explicit_fields.osml (limited to 'testdata') diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index fa78c17..e27c81e 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -286,7 +286,13 @@ enum class ParserFlag { * Set to the boolean value "true" if the head section of a file has passed. * This happens once the first non-import tag is reached. */ - POST_HEAD + POST_HEAD, + + /** + * Set to the boolean value "true" if explicit fields may no longer be + * defined inside a structure element. + */ + POST_EXPLICIT_FIELDS }; /** @@ -797,6 +803,7 @@ public: bool resolveFieldDescriptor(const std::string &name, Handle owner, Logger &logger, ResolutionResultCallback resultCallback); + /** * Tries to resolve all currently deferred resolution steps. The list of * pending deferred resolutions is cleared after this function has run. diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index e959b9a..1df3cb3 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -98,6 +98,9 @@ void DocumentChildHandler::createPath(const NodeVector &path, manager(), scope().getLeaf(), parent->getDescriptor()->getFieldDescriptorIndex(), true)}; scope().push(field); + + // Generally allow explicit fields in the new field + scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false); } void DocumentChildHandler::createPath(const size_t &firstFieldIdx, @@ -113,6 +116,9 @@ void DocumentChildHandler::createPath(const size_t &firstFieldIdx, parent = static_cast(transparent.get()); createPath(path, parent, 2); + + // Generally allow explicit fields in the new field + scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false); } bool DocumentChildHandler::start(Variant::mapType &args) @@ -170,12 +176,25 @@ bool DocumentChildHandler::start(Variant::mapType &args) ssize_t newFieldIdx = parent->getDescriptor()->getFieldDescriptorIndex(name()); if (newFieldIdx != -1) { - Rooted field{new DocumentField( - manager(), parentNode, newFieldIdx, false)}; - field->setLocation(location()); - scope().push(field); - isExplicitField = true; - return true; + // Check whether explicit fields are allowed here, if not + if (scope().getFlag(ParserFlag::POST_EXPLICIT_FIELDS)) { + logger().note( + std::string( + "Data or structure commands have already been " + "given, command \"") + + name() + std::string( + "\" is not interpreted explicit " + "field. Move explicit field " + "references to the beginning."), + location()); + } else { + Rooted field{new DocumentField( + manager(), parentNode, newFieldIdx, false)}; + field->setLocation(location()); + scope().push(field); + isExplicitField = true; + return true; + } } } @@ -218,11 +237,17 @@ bool DocumentChildHandler::start(Variant::mapType &args) parent->getDescriptor()->getFieldDescriptorIndex(); } // create the entity for the new element at last. - //TODO: REMOVE + // TODO: REMOVE strct_name = strct->getName(); entity = parent->createChildStructuredEntity(strct, lastFieldIdx, args, nameAttr); } + + // We're past the region in which explicit fields can be defined in the + // parent structure element + scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, true); + + // Bush the entity onto the stack entity->setLocation(location()); scope().push(entity); return true; @@ -271,6 +296,10 @@ bool DocumentChildHandler::fieldStart(bool &isDefault, size_t fieldIdx) new DocumentField(manager(), parentNode, fieldIdx, false)}; field->setLocation(location()); scope().push(field); + + // Generally allow explicit fields in the new field + scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false); + return true; } @@ -334,6 +363,10 @@ bool DocumentChildHandler::convertData(Handle field, bool DocumentChildHandler::data(Variant &data) { + // We're past the region in which explicit fields can be defined in the + // parent structure element + scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, true); + Rooted parentField = scope().getLeaf(); assert(parentField->isa(&RttiTypes::DocumentField)); diff --git a/test/formats/osml/OsmlParserTest.cpp b/test/formats/osml/OsmlParserTest.cpp index 4cda20a..5127b32 100644 --- a/test/formats/osml/OsmlParserTest.cpp +++ b/test/formats/osml/OsmlParserTest.cpp @@ -172,5 +172,32 @@ TEST(OsmlParser, structWithNoField) ASSERT_TRUE(node->isa(&RttiTypes::Document)); } +TEST(OsmlParser, invalidExplicitFields) +{ + OsmlStandaloneEnvironment env(logger); + logger.reset(); + + ASSERT_FALSE(logger.hasError()); + Rooted node = env.parse("invalid_explicit_fields.osml", "", "", + RttiSet{&RttiTypes::Node}); + ASSERT_TRUE(logger.hasError()); + + ASSERT_TRUE(node != nullptr); + ASSERT_TRUE(node->isa(&RttiTypes::Document)); +} + +TEST(OsmlParser, explicitFields) +{ + OsmlStandaloneEnvironment env(logger); + logger.reset(); + + Rooted node = env.parse("explicit_fields.osml", "", "", + RttiSet{&RttiTypes::Node}); + ASSERT_FALSE(logger.hasError()); + + ASSERT_TRUE(node != nullptr); + ASSERT_TRUE(node->isa(&RttiTypes::Document)); +} + } diff --git a/testdata/osmlparser/explicit_fields.osml b/testdata/osmlparser/explicit_fields.osml new file mode 100644 index 0000000..a9ba1a3 --- /dev/null +++ b/testdata/osmlparser/explicit_fields.osml @@ -0,0 +1,16 @@ +\document + +\domain#test + \struct#a[isRoot=true] + \primitive#b[type=string,isSubtree=true] + \primitive#c[type=string,isSubtree=true] + \primitive#d[type=string,isSubtree=false] + + +\a{! + \b{test} + \c{test} + test + test + test +} diff --git a/testdata/osmlparser/invalid_explicit_fields.osml b/testdata/osmlparser/invalid_explicit_fields.osml new file mode 100644 index 0000000..9986204 --- /dev/null +++ b/testdata/osmlparser/invalid_explicit_fields.osml @@ -0,0 +1,16 @@ +\document + +\domain#test + \struct#a[isRoot=true] + \primitive#b[type=string,isSubtree=true] + \primitive#c[type=string,isSubtree=true] + \primitive#d[type=string,isSubtree=false] + + +\a{! + \b{test} + test + \c{test} + test + test +} -- cgit v1.2.3 From a36be9501898d3bd2b7c85c2225bff2217dcde72 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 18 Feb 2015 16:32:23 +0100 Subject: restructured domains and deleted as many duplicates from testdata as possible. --- data/domain/bibliography.osxml | 33 ++++++++++---- data/domain/meta.osxml | 14 +++++- testdata/osxmlparser/affiliation.osxml | 10 ---- testdata/osxmlparser/bibliography_domain.osxml | 26 ----------- testdata/osxmlparser/color.osxml | 18 -------- testdata/osxmlparser/complex_book.osxml | 63 ++++++++++++-------------- testdata/osxmlparser/email.osxml | 8 ---- testdata/osxmlparser/generic.osxml | 37 --------------- testdata/osxmlparser/lists_domain.osxml | 26 ----------- testdata/osxmlparser/meta_domain.osxml | 35 -------------- testdata/osxmlparser/test.osxml | 15 ------ testdata/osxmlparser/version.osxml | 8 ---- 12 files changed, 65 insertions(+), 228 deletions(-) delete mode 100644 testdata/osxmlparser/affiliation.osxml delete mode 100644 testdata/osxmlparser/bibliography_domain.osxml delete mode 100644 testdata/osxmlparser/color.osxml delete mode 100644 testdata/osxmlparser/email.osxml delete mode 100644 testdata/osxmlparser/generic.osxml delete mode 100644 testdata/osxmlparser/lists_domain.osxml delete mode 100644 testdata/osxmlparser/meta_domain.osxml delete mode 100644 testdata/osxmlparser/test.osxml delete mode 100644 testdata/osxmlparser/version.osxml (limited to 'testdata') diff --git a/data/domain/bibliography.osxml b/data/domain/bibliography.osxml index 11e2606..5953e5f 100644 --- a/data/domain/bibliography.osxml +++ b/data/domain/bibliography.osxml @@ -12,16 +12,31 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/domain/meta.osxml b/data/domain/meta.osxml index 67ba1c9..d214921 100644 --- a/data/domain/meta.osxml +++ b/data/domain/meta.osxml @@ -21,14 +21,24 @@ - - + + + + + + + + + + + diff --git a/testdata/osxmlparser/affiliation.osxml b/testdata/osxmlparser/affiliation.osxml deleted file mode 100644 index d84dc30..0000000 --- a/testdata/osxmlparser/affiliation.osxml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/testdata/osxmlparser/bibliography_domain.osxml b/testdata/osxmlparser/bibliography_domain.osxml deleted file mode 100644 index 53ba531..0000000 --- a/testdata/osxmlparser/bibliography_domain.osxml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/color.osxml b/testdata/osxmlparser/color.osxml deleted file mode 100644 index 17adea4..0000000 --- a/testdata/osxmlparser/color.osxml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/complex_book.osxml b/testdata/osxmlparser/complex_book.osxml index b610454..8fff93d 100644 --- a/testdata/osxmlparser/complex_book.osxml +++ b/testdata/osxmlparser/complex_book.osxml @@ -1,13 +1,12 @@ - - - - + + + + @@ -19,40 +18,18 @@ [ikant,philo.albertus-koenigsberg,de] [Logic and Metaphysics, Faculty of Philosophy, Albertus-University Königsberg] - + [1,0,0] - - - Beantwortung der Frage: Was ist Aufklärung? - - - - Was ist Aufklärung? - - Aufklärung ist der Ausgang des Menschen aus seiner - selbstverschuldeten Unmündigkeit. Unmündigkeit ist - das Unvermögen, sich seines Verstandes ohne Leitung eines anderen zu - bedienen. Selbstverschuldet ist diese Unmündigkeit, wenn - die Ursache derselben nicht am Mangel des Verstandes, sondern der - Entschließung und des Mutes liegt, sich seiner ohne Leitung eines - andern zu bedienen. - Sapere aude! Habe Mut, dich deines eigenen Verstandes zu - bedienen! ist also der Wahlspruch der Aufklärung. - - Dezember-Heft + Dezember-Heft Berlinische Monatsschrift 1784 {481-494} - Kleine Schriften + Kleine Schriften Immanuel Kant @@ -62,7 +39,7 @@ Neuwied - Zerstreute Aufsätze + Zerstreute Aufsätze Immanuel Kant @@ -72,7 +49,7 @@ Frankfurt und Leipzig - Sämmtliche kleine Schriften + Sämmtliche kleine Schriften Immanuel Kant @@ -82,7 +59,7 @@ Königsberg u. Leipzig - I. Kant's vermischte Schriften + I. Kant's vermischte Schriften Immanuel Kant @@ -92,7 +69,7 @@ Halle - Vorzügliche kleine Schriften und Aufsätze + Vorzügliche kleine Schriften und Aufsätze Immanuel Kant @@ -102,5 +79,23 @@ Leipzig + + + Beantwortung der Frage: Was ist Aufklärung? + + + + Was ist Aufklärung? + + Aufklärung ist der Ausgang des Menschen aus seiner + selbstverschuldeten Unmündigkeit. Unmündigkeit ist + das Unvermögen, sich seines Verstandes ohne Leitung eines anderen zu + bedienen. Selbstverschuldet ist diese Unmündigkeit, wenn + die Ursache derselben nicht am Mangel des Verstandes, sondern der + Entschließung und des Mutes liegt, sich seiner ohne Leitung eines + andern zu bedienen. + Sapere aude! Habe Mut, dich deines eigenen Verstandes zu + bedienen! ist also der Wahlspruch der Aufklärung. + diff --git a/testdata/osxmlparser/email.osxml b/testdata/osxmlparser/email.osxml deleted file mode 100644 index 325f89a..0000000 --- a/testdata/osxmlparser/email.osxml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/testdata/osxmlparser/generic.osxml b/testdata/osxmlparser/generic.osxml deleted file mode 100644 index 799ed41..0000000 --- a/testdata/osxmlparser/generic.osxml +++ /dev/null @@ -1,37 +0,0 @@ - - - ./color.osxml - - - none - dotted - dashed - solid - double - groove - ridge - inset - outset - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/lists_domain.osxml b/testdata/osxmlparser/lists_domain.osxml deleted file mode 100644 index cacb9cc..0000000 --- a/testdata/osxmlparser/lists_domain.osxml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/meta_domain.osxml b/testdata/osxmlparser/meta_domain.osxml deleted file mode 100644 index 52dffc5..0000000 --- a/testdata/osxmlparser/meta_domain.osxml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/test.osxml b/testdata/osxmlparser/test.osxml deleted file mode 100644 index e492488..0000000 --- a/testdata/osxmlparser/test.osxml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/testdata/osxmlparser/version.osxml b/testdata/osxmlparser/version.osxml deleted file mode 100644 index 0d52736..0000000 --- a/testdata/osxmlparser/version.osxml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - -- cgit v1.2.3