stevedlawrence commented on code in PR #1579: URL: https://github.com/apache/daffodil/pull/1579#discussion_r2445626036
########## daffodil-test/src/test/resources/org/apache/daffodil/section15/choice_groups/ChoiceBranches.tdml: ########## @@ -0,0 +1,112 @@ +<?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. +--> + +<tdml:testSuite suiteName="choiceBranches" description="Tests for choice branch selection" + 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:ex="http://example.com" + xmlns:fn="http://www.w3.org/2005/xpath-functions" + xmlns="http://example.com"> + + <tdml:defineSchema name="choiceBranches"> + <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/> + <dfdl:format ref="ex:GeneralFormat"/> + + <xs:group name="empty"> + <xs:sequence> + <xs:element name="empty" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="1" + dfdl:outputValueCalc="{ '0' }"/> + </xs:sequence> + </xs:group> + + <xs:group name="notEmpty"> + <xs:sequence> + <xs:element name="notEmpty" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="1" + dfdl:outputValueCalc="{ '1' }"/> + </xs:sequence> + </xs:group> + + <xs:element name="e1" dfdl:lengthKind="implicit"> + <xs:complexType> + <xs:sequence> + <xs:choice> + <xs:sequence dfdl:hiddenGroupRef="ex:empty"/> + <xs:sequence> + <xs:sequence dfdl:hiddenGroupRef="ex:notEmpty"/> + <xs:element name="char" type="xs:string" minOccurs="0" dfdl:lengthKind="explicit" dfdl:length="1"/> + </xs:sequence> + </xs:choice> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="e2" dfdl:lengthKind="implicit"> + <xs:complexType> + <xs:choice> + <xs:sequence> + <xs:sequence dfdl:hiddenGroupRef="ex:notEmpty"/> + <xs:element name="char" type="xs:string" minOccurs="0" dfdl:lengthKind="explicit" dfdl:length="1"/> + </xs:sequence> + <xs:sequence dfdl:hiddenGroupRef="ex:empty"/> + </xs:choice> + </xs:complexType> + </xs:element> + Review Comment: I think these schemas are only considering the "empty" case and not things like non-hidden OVCs or defaulatable elements that can be unparsed without being in the infoset. I *think* if those are in the schema before a hidden group ref, for example, then they should be chosen as the default unparse branch, but I think that currently isn't the case. We always prefer a hidden group ref branch even if it appears later in the choice. I think the tests we really need is multiple schemas that have the same empty-ish branches but in different orders and it should always unparse whichever appears first in the schema. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
