This is an automated email from the ASF dual-hosted git repository.

mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/daffodil.git

commit 7b17eb0c47908d620521205ca50a8c052fa1f934
Author: Michael Beckerle <[email protected]>
AuthorDate: Wed Apr 21 13:26:28 2021 -0400

    Add tests to illustrate SSP 'never' bugs and poor diagnostics
    
    DAFFODIL-2499, DAFFODIL-2496
---
 .../org/apache/daffodil/usertests/SepTests.tdml    | 152 ++++++++++++++++++++-
 .../apache/daffodil/usertests/TestSepTests.scala   |   8 ++
 2 files changed, 159 insertions(+), 1 deletion(-)

diff --git 
a/daffodil-test/src/test/resources/org/apache/daffodil/usertests/SepTests.tdml 
b/daffodil-test/src/test/resources/org/apache/daffodil/usertests/SepTests.tdml
index d3a3955..faeb71b 100644
--- 
a/daffodil-test/src/test/resources/org/apache/daffodil/usertests/SepTests.tdml
+++ 
b/daffodil-test/src/test/resources/org/apache/daffodil/usertests/SepTests.tdml
@@ -23,7 +23,8 @@
        xmlns:xsd="http://www.w3.org/2001/XMLSchema";
        xmlns:xs="http://www.w3.org/2001/XMLSchema";
        xmlns:ex="http://example.com";
-       xmlns:fn="http://www.w3.org/2005/xpath-functions";>
+       xmlns:fn="http://www.w3.org/2005/xpath-functions";
+       xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions";>
 
        <tdml:defineSchema name="s1" elementFormDefault="unqualified">
 
@@ -168,4 +169,153 @@
                </tdml:errors>
        </tdml:parserTestCase>
 
+       <tdml:defineSchema name="s3" elementFormDefault="unqualified">
+
+                       <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+                       <dfdl:format
+                               ref="ex:GeneralFormat"
+                               representation="text"
+                               lengthKind="delimited"
+                               separatorPosition="infix"
+                         dfdlx:emptyElementParsePolicy="treatAsEmpty" />
+               <!--
+               Note: dfdlx:emptyElementParsePolicy should become regular DFDL 
emptyElementParsePolicy
+               once implemented in DAFFODIL-2496. The enum 'treatAsMissing' is 
renamed to 'treatAsAbsent'
+               -->
+
+                       <xs:element name="file1">
+        <xs:complexType>
+          <xs:sequence dfdl:separator="," dfdl:separatorPosition="infix"
+            dfdl:separatorSuppressionPolicy="never">
+            <xs:element name="given-name" type="xs:string" minOccurs="0" 
maxOccurs="3" />
+            <xs:element name="surname" type="xs:string" minOccurs="0"/>
+            <xs:element name="phone" type="xs:string" minOccurs="0" 
maxOccurs="6" />
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+
+               <!-- Same, but has minOccurs=maxOccurs for the arrays.
+                That makes all array elements "required" -->
+                       <xs:element name="file2">
+                               <xs:complexType>
+                                       <xs:sequence dfdl:separator="," 
dfdl:separatorPosition="infix"
+                                                                               
         dfdl:separatorSuppressionPolicy="never">
+                                               <xs:element name="given-name" 
type="xs:string" minOccurs="3" maxOccurs="3" />
+                                               <xs:element name="surname" 
type="xs:string" />
+                                               <xs:element name="phone" 
type="xs:string" minOccurs="6" maxOccurs="6" />
+                                       </xs:sequence>
+                               </xs:complexType>
+                       </xs:element>
+
+       </tdml:defineSchema>
+
+       <!-- Test for DAFFODIL-2499. empty strings should not be creating empty 
elements here. -->
+       <tdml:parserTestCase name="test_sep_ssp_never_1" root="file1" model="s3"
+         implementations="daffodil ibm">
+               <tdml:document>madonna,,,,,,,,,</tdml:document>
+               <tdml:infoset>
+                       <tdml:dfdlInfoset>
+                               <ex:file1>
+                                       <given-name>madonna</given-name>
+                               </ex:file1>
+                       </tdml:dfdlInfoset>
+               </tdml:infoset>
+       </tdml:parserTestCase>
+
+       <tdml:parserTestCase name="test_sep_ssp_never_2" root="file2" model="s3"
+                                                                               
         implementations="daffodil ibm">
+               <tdml:document>madonna,,,,,,,,,</tdml:document>
+               <tdml:infoset>
+                       <tdml:dfdlInfoset>
+                               <ex:file2>
+                                       <given-name>madonna</given-name>
+                                       <given-name></given-name>
+                                       <given-name></given-name>
+                                       <surname></surname>
+                                       <phone></phone>
+                                       <phone></phone>
+                                       <phone></phone>
+                                       <phone></phone>
+                                       <phone></phone>
+                                       <phone></phone>
+                               </ex:file2>
+                       </tdml:dfdlInfoset>
+               </tdml:infoset>
+       </tdml:parserTestCase>
+
+       <!--
+       This schema identical to s3, except for the 
dfdlx:emptyElementParsePolicy is treatAsMissing
+       -->
+       <tdml:defineSchema name="s4" elementFormDefault="unqualified">
+
+               <xs:include 
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+               <dfdl:format
+                       ref="ex:GeneralFormat"
+                       representation="text"
+                       lengthKind="delimited"
+                       separatorPosition="infix"
+                       dfdlx:emptyElementParsePolicy="treatAsMissing" />
+               <!--
+               Note: dfdlx:emptyElementParsePolicy should become regular DFDL 
emptyElementParsePolicy
+               once implemented in DAFFODIL-2496. The enum 'treatAsMissing' is 
renamed to 'treatAsAbsent'
+               -->
+
+               <!--
+               treatAsMissing should have no effect here, because everything 
is optional.
+               -->
+               <xs:element name="file1">
+                       <xs:complexType>
+                               <xs:sequence dfdl:separator="," 
dfdl:separatorPosition="infix"
+                                                                               
 dfdl:separatorSuppressionPolicy="never">
+                                       <xs:element name="given-name" 
type="xs:string" minOccurs="0" maxOccurs="3" />
+                                       <xs:element name="surname" 
type="xs:string" minOccurs="0"/>
+                                       <xs:element name="phone" 
type="xs:string" minOccurs="0" maxOccurs="6" />
+                               </xs:sequence>
+                       </xs:complexType>
+               </xs:element>
+
+               <!-- Same, but has minOccurs=maxOccurs for the arrays.
+                That makes all array elements "required"
+
+                treatAsMissing causes this to fail. Required empty 
non-defaultable is an error in that case.
+                (note: treatAsMissing will become treatAsAbsent DAFFODIL-2496)
+                -->
+               <xs:element name="file2">
+                       <xs:complexType>
+                               <xs:sequence dfdl:separator="," 
dfdl:separatorPosition="infix"
+                                                                               
 dfdl:separatorSuppressionPolicy="never">
+                                       <xs:element name="given-name" 
type="xs:string" minOccurs="3" maxOccurs="3" />
+                                       <xs:element name="surname" 
type="xs:string" />
+                                       <xs:element name="phone" 
type="xs:string" minOccurs="6" maxOccurs="6" />
+                               </xs:sequence>
+                       </xs:complexType>
+               </xs:element>
+
+       </tdml:defineSchema>
+
+       <!-- Test for DAFFODIL-2499. empty strings should not be creating empty 
elements here. -->
+       <tdml:parserTestCase name="test_sep_ssp_never_3" root="file1" model="s4"
+                                                                               
         implementations="daffodil ibm">
+               <tdml:document>madonna,,,,,,,,,</tdml:document>
+               <tdml:infoset>
+                       <tdml:dfdlInfoset>
+                               <ex:file1>
+                                       <given-name>madonna</given-name>
+                               </ex:file1>
+                       </tdml:dfdlInfoset>
+               </tdml:infoset>
+       </tdml:parserTestCase>
+
+       <tdml:parserTestCase name="test_sep_ssp_never_4" root="file2" model="s4"
+                                                                               
         implementations="daffodil ibm">
+               <tdml:document>madonna,,,,,,,,,</tdml:document>
+               <tdml:errors>
+                       <tdml:error>Parse Error</tdml:error>
+                       <tdml:error>emptyElementParsePolicy</tdml:error>
+                       <tdml:error>treatAsMissing</tdml:error><!-- will change 
to treatAsAbsent DAFFODIL-2496 -->
+                       <tdml:error>required</tdml:error>
+               </tdml:errors>
+       </tdml:parserTestCase>
+
+
 </tdml:testSuite>
\ No newline at end of file
diff --git 
a/daffodil-test/src/test/scala/org/apache/daffodil/usertests/TestSepTests.scala 
b/daffodil-test/src/test/scala/org/apache/daffodil/usertests/TestSepTests.scala
index 170dfed..946c3ab 100644
--- 
a/daffodil-test/src/test/scala/org/apache/daffodil/usertests/TestSepTests.scala
+++ 
b/daffodil-test/src/test/scala/org/apache/daffodil/usertests/TestSepTests.scala
@@ -44,4 +44,12 @@ class TestSepTests {
   // @Test def test_sep_trailingEmptyStrict_1(): Unit = { 
runner.runOneTest("test_sep_trailingEmptyStrict_1") }
   @Test def test_sep_trailingEmptyStrict_2(): Unit = { 
runner.runOneTest("test_sep_trailingEmptyStrict_2") }
 
+  // DAFFODIL-2499 - separatorSuppressionPolicy 'never'
+  // @Test def test_sep_ssp_never_1(): Unit = { 
runner.runOneTest("test_sep_ssp_never_1") }
+  @Test def test_sep_ssp_never_2(): Unit = { 
runner.runOneTest("test_sep_ssp_never_2") }
+  // DAFFODIL-2499 - separatorSuppressionPolicy 'never'
+  // @Test def test_sep_ssp_never_3(): Unit = { 
runner.runOneTest("test_sep_ssp_never_3") }
+  // DAFFODIL-2496 - implement DFDL official emptyElementParsePolicy property
+  // @Test def test_sep_ssp_never_4(): Unit = { 
runner.runOneTest("test_sep_ssp_never_4") }
+
 }

Reply via email to