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 2023/04/19 14:19:04 UTC

[daffodil] branch main updated: Fix textStandardZeroRep to be "" (off) not "0"

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 38f387109 Fix textStandardZeroRep to be "" (off) not "0"
38f387109 is described below

commit 38f387109c1a4c622af2eda3d6aed1b4bf1a2c04
Author: Michael Beckerle <mb...@apache.org>
AuthorDate: Tue Apr 18 16:06:28 2023 -0400

    Fix textStandardZeroRep to be "" (off) not "0"
    
    Setting this to "" turns the feature off so that there is no
    special zero rep.
    
    Thie avoids the need for users to know about textStandardZeroRep
    unless they need to use it. The dfdl:textNumberPattern defines
    digits to be output, and that controls the format of numbers without any
    special case represntation for zero in the GeneralFormat that is used
    by default by many schemas.
    
    Deprecation/Compatibility
    
    The property textStandardZeroRep used to be defined to be "0" which
    is a mistake. However, existing schemas may be depending on this, or
    they may not be depending on this, but simply have tests which have expected
    data output containing the value 0.0 with "0" as the text representation.
    With this change to dfdl:textStandardZeroRep="" those tests may be broken.
    
    DAFFODIL-2147
---
 .../apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd |  2 +-
 .../text_number_props/TextNumberPropsUnparse.tdml  | 63 +++++++++++++++++++++-
 .../TestTextNumberPropsUnparse.scala               |  8 +++
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd b/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd
index af7e00de7..ddc6f9626 100644
--- a/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd
+++ b/daffodil-lib/src/main/resources/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd
@@ -92,7 +92,7 @@
           textStandardGroupingSeparator=","
           textStandardInfinityRep="Inf"
           textStandardNaNRep="NaN"
-          textStandardZeroRep="0"
+          textStandardZeroRep=""
           textStringJustification="left"
           textStringPadCharacter="%SP;"
           textTrimKind="none"
diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberPropsUnparse.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberPropsUnparse.tdml
index 2829b663c..29581a1fd 100644
--- a/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberPropsUnparse.tdml
+++ b/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberPropsUnparse.tdml
@@ -142,7 +142,7 @@
       <xs:element name="e17" type="ex:st10" dfdl:lengthKind="delimited" dfdl:textPadKind="padChar" dfdl:textStringPadCharacter="%ES;" dfdl:textStringJustification="right" />
 
   </tdml:defineSchema>
-  
+
 <!--
       Test Name: unparseDelimitedPaddedString01
       Schema: delimitedStringsPadding
@@ -679,4 +679,65 @@
     <tdml:document><![CDATA[0.12]]></tdml:document>
   </tdml:unparserTestCase>
 
+
+  <tdml:defineSchema name="textNumbers">
+    <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+    <dfdl:format ref="ex:GeneralFormat"/>
+
+    <xs:element name="e18" type="xs:double"
+                dfdl:textNumberCheckPolicy="strict"
+                dfdl:textNumberPattern="000.00"
+                dfdl:lengthKind="delimited"/>
+
+    <xs:element name="e19" type="xs:double"
+                dfdl:textNumberCheckPolicy="strict"
+                dfdl:textNumberPattern="000.00"
+                dfdl:textStandardZeroRep="zero"
+                dfdl:lengthKind="delimited"/>
+
+    <!--
+    This element demonstrates why the default value for dfdl:textStandardZeroRep needs to be "" (turns the feature off)
+    which is because if it is defined to be "0", then it overrides the dfdl:textNumberPattern.
+
+    People shouldn't even have to remember this property exists unless they need it for their format. So by default
+    it needs to be off.
+
+    People waste quite a bit of time on this, permuting their textNumberPattern, but not understanding why it is
+    not working.
+    -->
+    <xs:element name="e20" type="xs:double"
+                dfdl:textNumberCheckPolicy="strict"
+                dfdl:textNumberPattern="000.00"
+                dfdl:textStandardZeroRep="0"
+                dfdl:lengthKind="delimited"/>
+
+  </tdml:defineSchema>
+
+  <tdml:unparserTestCase name="textStandardZeroRepNotDefinedByDefault" model="textNumbers" root="e18" roundTrip="true">
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:e18>0.0</ex:e18>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+    <tdml:document>000.00</tdml:document>
+  </tdml:unparserTestCase>
+
+  <tdml:unparserTestCase name="textStandardZeroRep1" model="textNumbers" root="e19" roundTrip="true">
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:e19>0.0</ex:e19>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+    <tdml:document>zero</tdml:document>
+  </tdml:unparserTestCase>
+
+  <tdml:unparserTestCase name="textStandardZeroRep2" model="textNumbers" root="e20" roundTrip="true">
+    <tdml:infoset>
+      <tdml:dfdlInfoset>
+        <ex:e20>0.0</ex:e20>
+      </tdml:dfdlInfoset>
+    </tdml:infoset>
+    <tdml:document>0</tdml:document>
+  </tdml:unparserTestCase>
+
 </tdml:testSuite>
diff --git a/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberPropsUnparse.scala b/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberPropsUnparse.scala
index 5b000338c..71a1bbd4e 100644
--- a/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberPropsUnparse.scala
+++ b/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberPropsUnparse.scala
@@ -109,4 +109,12 @@ class TestTextNumberPropsUnparse {
   @Test def test_unparse_tnp_04(): Unit = { runner.runOneTest("unparse_tnp_04") }
   @Test def test_unparse_tnp_05a(): Unit = { runner.runOneTest("unparse_tnp_05a") }
   @Test def test_unparse_tnp_05b(): Unit = { runner.runOneTest("unparse_tnp_05b") }
+
+  @Test def test_textStandardZeroRepNotDefinedByDefault(): Unit =
+    runner.runOneTest("textStandardZeroRepNotDefinedByDefault")
+
+  @Test def test_textStandardZeroRep1(): Unit = runner.runOneTest("textStandardZeroRep1")
+
+  @Test def test_textStandardZeroRep2(): Unit = runner.runOneTest("textStandardZeroRep2")
+
 }