summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-04 21:12:32 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-04 21:12:32 +0100
commit0ff4b8bbd46c1561490aeacf3814d1678fb8d403 (patch)
treee1aff4520f5615bddaf41c926ede761a342233f1
parentf02dbb53a79ae3fcc69f680782b087265b826299 (diff)
got headings domain to work.
-rw-r--r--test/plugins/xml/XmlParserTest.cpp28
-rw-r--r--testdata/xmlparser/headings_domain.oxm14
2 files changed, 30 insertions, 12 deletions
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp
index c493643..2d0cb6f 100644
--- a/test/plugins/xml/XmlParserTest.cpp
+++ b/test/plugins/xml/XmlParserTest.cpp
@@ -114,7 +114,7 @@ static void checkFieldDescriptor(
FieldDescriptor::FieldType type = FieldDescriptor::FieldType::TREE,
Handle<Type> primitiveType = nullptr, bool optional = false)
{
- ASSERT_FALSE(n.isNull());
+ ASSERT_FALSE(n == nullptr);
Handle<FieldDescriptor> field = n.cast<FieldDescriptor>();
ASSERT_FALSE(field.isNull());
ASSERT_EQ(name, field->getName());
@@ -131,7 +131,7 @@ static void checkFieldDescriptor(
static void checkFieldDescriptor(
Handle<Descriptor> desc, NodeVector<StructuredClass> children,
- const std::string &name = "",
+ const std::string &name = DEFAULT_FIELD_NAME,
FieldDescriptor::FieldType type = FieldDescriptor::FieldType::TREE,
Handle<Type> primitiveType = nullptr, bool optional = false)
{
@@ -183,9 +183,27 @@ TEST(XmlParser, domainParsing)
// check parent handling.
Rooted<Node> headings_domain_node =
env.parse("headings_domain.oxm", "", "", RttiSet{&RttiTypes::Domain});
- //TODO: Unfortunately this does not work yet.
- //ASSERT_FALSE(headings_domain_node == nullptr);
- //ASSERT_FALSE(logger.hasError());
+ ASSERT_FALSE(headings_domain_node == nullptr);
+ ASSERT_FALSE(logger.hasError());
+ Rooted<Domain> headings_domain = headings_domain_node.cast<Domain>();
+ // now there should be a heading struct.
+ Rooted<StructuredClass> heading =
+ checkStructuredClass("heading", "heading", headings_domain, single,
+ nullptr, nullptr, true, false);
+ // which should allow text content
+ checkFieldDescriptor(heading, {text});
+ // and each struct in the book domain (except for text) should have a
+ // heading field now.
+ checkFieldDescriptor(book, {heading}, "heading",
+ FieldDescriptor::FieldType::SUBTREE, nullptr, true);
+ checkFieldDescriptor(chapter, {heading}, "heading",
+ FieldDescriptor::FieldType::SUBTREE, nullptr, true);
+ checkFieldDescriptor(section, {heading}, "heading",
+ FieldDescriptor::FieldType::SUBTREE, nullptr, true);
+ checkFieldDescriptor(subsection, {heading}, "heading",
+ FieldDescriptor::FieldType::SUBTREE, nullptr, true);
+ checkFieldDescriptor(paragraph, {heading}, "heading",
+ FieldDescriptor::FieldType::SUBTREE, nullptr, true);
}
}
diff --git a/testdata/xmlparser/headings_domain.oxm b/testdata/xmlparser/headings_domain.oxm
index f83843c..2238792 100644
--- a/testdata/xmlparser/headings_domain.oxm
+++ b/testdata/xmlparser/headings_domain.oxm
@@ -3,31 +3,31 @@
<import rel="domain" src="./book_domain.oxm"/>
- <struct name="heading" cardinality="{0-1}" transparent="true">
+ <struct name="heading" cardinality="1" transparent="true">
<!-- The parent mechanism is a curious thing. Remind yourself
that parent-child-relationship in this sense are mediated
by fields. So we must either reference a field that is
already there or declare a new one on the fly. -->
<parent name="book.book">
- <field name="heading" isSubtree="true"/>
+ <field name="heading" isSubtree="true" optional="true"/>
</parent>
<parent name="book.chapter">
- <field name="heading" isSubtree="true"/>
+ <field name="heading" isSubtree="true" optional="true"/>
</parent>
<parent name="book.section">
- <field name="heading" isSubtree="true"/>
+ <field name="heading" isSubtree="true" optional="true"/>
</parent>
<parent name="book.subsection">
- <field name="heading" isSubtree="true"/>
+ <field name="heading" isSubtree="true" optional="true"/>
</parent>
<parent name="book.paragraph">
- <field name="heading" isSubtree="true"/>
+ <field name="heading" isSubtree="true" optional="true"/>
</parent>
<!-- regarding its fields we have a problem here. We do not want to
declare a new field, because in fact we want to allow every
bit of content that a paragraph would allow - also considering
possible extensions of paragraph by other domains.
So we need to reference the default field of paragraph. -->
- <fieldRef name="book.paragraph."/>
+ <fieldRef name="book.paragraph.$default"/>
</struct>
</domain>