stevedlawrence commented on code in PR #1357:
URL: https://github.com/apache/daffodil/pull/1357#discussion_r1827834606
##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2769,41 +2770,52 @@ case class Infoset(i: NodeSeq, parent: TestCase) {
case class DFDLInfoset(di: Node, parent: Infoset) {
- private lazy val infosetNodeSeq = {
- val testCase: TestCase = parent.parent
- val loader = testCase.parent.loader
- val optDataSchema: Option[URI] = {
- testCase.optSchemaFileURI.orElse(testCase.optEmbeddedSchema.map {
_.uriForLoading })
- }
- val src =
- (di \ "@type").toString match {
- case "infoset" | "" => {
- val rawElem = di.child.filter {
- _.isInstanceOf[scala.xml.Elem]
- }.head
- UnitTestSchemaSource(rawElem, testCase.tcName)
- }
- case "file" => {
- val path = di.text.trim()
- val maybeURI = parent.parent.parent.findTDMLResource(path)
- val uri = maybeURI.getOrElse(
- throw new FileNotFoundException(
- "TDMLRunner: infoset file '" + path + "' was not found"
- )
- )
- URISchemaSource(uriToDiagnosticFile(uri), uri)
- }
- case value => Assert.abort("Unknown value for type attribute on
dfdlInfoset: " + value)
- }
+ private lazy val testCase: TestCase = parent.parent
+ private lazy val loader = testCase.parent.loader
+ private val ty: String = {
+ val t = (di \ "@type").text.trim
+ if (t.isEmpty) "infoset" else t
+ }
+
+ private val elemOrStr: Either[Elem, String] = {
+ val (elems, others) = di.child.partition(_.isInstanceOf[scala.xml.Elem])
+ (elems, others.text.trim) match {
+ case (Seq(elem: Elem), "") if (ty == "infoset") => Left(elem)
+ case (Seq(), str) if (ty == "file") => Right(str)
+ case _ =>
+ Assert.usageError(
+ """dfdlInfoset element must contain a single root element or a file
path (when 'type="file"')."""
+ )
+ }
+ }
Review Comment:
Semi related, I wonder if we made a mistake by adding a `type` attribute to
`dfdlInfoset`? Maybe instead `tdml:infoset` should be a choice of different
children, so for example a file type would be specified like this instead:
```xml
<tdml:infoset>
<tdml:file>/path/to/file.xml</tdml:file>
</tdml:infoset>
```
It's maybe too late now since lots of things use `type="file"` but maybe in
the future the use of `type="foo"` to define the format of the children should
be avoided? It probably would have simplified this logic a bit.
--
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]