You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2022/08/09 15:10:07 UTC
[daffodil] branch main updated: Add tests to show fixed len + nillable case.
This is an automated email from the ASF dual-hosted git repository.
mbeckerle pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 87a0d8b65 Add tests to show fixed len + nillable case.
87a0d8b65 is described below
commit 87a0d8b653ea6b738a033b2f4c8c4e19b8235139
Author: Michael Beckerle <mb...@apache.org>
AuthorDate: Mon Aug 8 15:41:41 2022 -0400
Add tests to show fixed len + nillable case.
Came up in user support.
DAFFODIL-2719
---
.../daffodil/section13/nillable/nillable2.tdml | 117 +++++++++++++++++++++
.../section13/nillable/TestNillable2.scala | 55 ++++++++++
2 files changed, 172 insertions(+)
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section13/nillable/nillable2.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section13/nillable/nillable2.tdml
new file mode 100644
index 000000000..8b69b3749
--- /dev/null
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section13/nillable/nillable2.tdml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<testSuite
+ xmlns:tns="http://example.com"
+ xmlns="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
+ xmlns:daf="urn:ogf:dfdl:2013:imp:daffodil.apache.org:2018:ext"
+ xmlns:ex="http://example.com"
+ defaultRoundTrip="true"
+ defaultValidation="on">
+
+ <tdml:defineSchema name="s" elementFormDefault="unqualified" useDefaultNamespace="false"
+ xmlns="http://www.w3.org/2001/XMLSchema">
+
+ <include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+ <dfdl:format
+ ref="ex:GeneralFormat"
+ textStringPadCharacter="%SP;"
+ nilKind="literalValue"
+ />
+
+ <element name="Foo"
+ dfdl:length="5"
+ dfdl:lengthKind="explicit"
+ dfdl:terminator="/"
+ dfdl:fillByte="%SP;">
+ <!--
+ The above achieves canonical unparse
+ as left-justified fixed length because
+ the fillByte will be used to fill unused
+ space on the right.
+
+ This only works for fixed length left-justified data.
+ If this was right-justified, this trick would not work.
+ -->
+ <complexType>
+ <sequence>
+ <!--
+ The below achieves trimming of spaces either side,
+ but only when parsing. Nothing is added when unparsing.
+ -->
+ <element name="value" nillable="true"
+ dfdl:nilValue="-"
+ dfdl:lengthKind="delimited"
+ dfdl:textStringJustification="center"
+ dfdl:textTrimKind="padChar"
+ dfdl:textPadKind="none">
+ <simpleType>
+ <restriction base="xs:string">
+ <enumeration value="AB"/>
+ <enumeration value="ABC"/>
+ </restriction>
+ </simpleType>
+ </element>
+ </sequence>
+ </complexType>
+ </element>
+
+ </tdml:defineSchema>
+
+ <parserTestCase name="foo1" root="Foo" model="s" roundTrip="onePass">
+ <document>- /</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:Foo xmlns=""><value xsi:nil="true"/></ex:Foo>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="foo2" root="Foo" model="s" roundTrip="twoPass">
+ <document> - /</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:Foo xmlns=""><value xsi:nil="true"/></ex:Foo>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="foo3" root="Foo" model="s" roundTrip="twoPass">
+ <document> AB /</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:Foo xmlns=""><value>AB</value></ex:Foo>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+ <parserTestCase name="foo4" root="Foo" model="s" roundTrip="onePass">
+ <document>AB /</document>
+ <infoset>
+ <dfdlInfoset>
+ <ex:Foo xmlns=""><value>AB</value></ex:Foo>
+ </dfdlInfoset>
+ </infoset>
+ </parserTestCase>
+
+</testSuite>
\ No newline at end of file
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section13/nillable/TestNillable2.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section13/nillable/TestNillable2.scala
new file mode 100644
index 000000000..cdb02ba0f
--- /dev/null
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section13/nillable/TestNillable2.scala
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.section13.nillable
+
+import org.junit.Test
+import org.apache.daffodil.tdml.Runner
+import org.junit.AfterClass
+
+object TestNillable2 {
+ val testDir = "/org/apache/daffodil/section13/nillable/"
+
+ val runner = Runner(testDir, "nillable2.tdml")
+
+ @AfterClass def shutDown(): Unit = {
+ runner.reset
+ }
+
+}
+
+class TestNillable2 {
+
+ import TestNillable2._
+
+ @Test def test_foo1(): Unit = {
+ runner.runOneTest("foo1")
+ }
+
+ @Test def test_foo2(): Unit = {
+ runner.runOneTest("foo2")
+ }
+
+ @Test def test_foo3(): Unit = {
+ runner.runOneTest("foo3")
+ }
+
+ @Test def test_foo4(): Unit = {
+ runner.runOneTest("foo4")
+ }
+
+}