Skip to content

Commit

Permalink
!fixup Add support for validation of length facet
Browse files Browse the repository at this point in the history
- add support for length, also set minLength and maxLength with the value of length, when hasLength is true, and those variables are queried
- ensure length and minLength and maxLength facets are not declared together (Xerces Error, but we have asserts incase Xerces validation is turned off)
- fix error message for isSimpleType check in computeMinMaxLength and length definitions
- add tests for validation=limited and validation=on
- added hexBinary tests including test with length=0

DAFFODIL-2842
  • Loading branch information
olabusayoT committed Mar 25, 2024
1 parent c62cbac commit 7fd68d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ trait ElementBase
Assert.invariant(hasLength)
schemaDefinitionUnless(
isSimpleType,
"Facet length is allowed only on types string and hexBinary.",
"Facet length is allowed only on simple types or types derived from simple types.",
)
typeDef match {
case _ if hasRepType => {
Expand Down Expand Up @@ -1037,7 +1037,7 @@ trait ElementBase
private def computeMinMaxLength: (java.math.BigDecimal, java.math.BigDecimal) = {
schemaDefinitionUnless(
isSimpleType,
"Facets minLength and maxLength are allowed only on types string and hexBinary.",
"Facets minLength and maxLength are allowed only on simple types or types derived from simple types.",
)
typeDef match {
case _ if hasRepType => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@
</xs:simpleType>
</xs:element>

<xs:element name="e2_8" dfdl:lengthKind="delimited" dfdl:encoding="iso-8859-1">
<xs:simpleType>
<xs:restriction base="xs:hexBinary">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name="e3_2" dfdl:lengthKind="delimited">
<xs:simpleType>
<xs:restriction base="ex:stMaxLength_2">
Expand Down Expand Up @@ -710,6 +718,30 @@
</tdml:dfdlInfoset>
</tdml:infoset>
</tdml:parserTestCase>

<tdml:parserTestCase name="validation_testFacets_03"
root="e2_8" model="TestFacets"
description="checks that int doesn't work with length facet"
validation="limited">

<tdml:document>
<tdml:documentPart type="byte">deadbeefdafada</tdml:documentPart>
</tdml:document>

<tdml:infoset>
<tdml:dfdlInfoset>
<ex:e2_8>DEADBEEFDAFADA</ex:e2_8>
</tdml:dfdlInfoset>
</tdml:infoset>

<tdml:validationErrors>

<tdml:error>e2_8</tdml:error>
<tdml:error>failed facet checks</tdml:error>
<tdml:error>facet length (0)</tdml:error>

</tdml:validationErrors>
</tdml:parserTestCase>
<!--
Test name: checkEnumeration_Pass_limited
Schema: TestFacets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class TestValidationErr {
@Test def test_validation_testFacets_02(): Unit = {
runner.runOneTest("validation_testFacets_02")
}
@Test def test_validation_testFacets_03(): Unit = {
runner.runOneTest("validation_testFacets_03")
}
@Test def test_validation_testFacets2_01(): Unit = {
runner.runOneTest("validation_testFacets2_01")
}
Expand Down

0 comments on commit 7fd68d5

Please sign in to comment.