andrewjc2000 commented on a change in pull request #394: URL: https://github.com/apache/incubator-daffodil/pull/394#discussion_r455970514
########## File path: daffodil-core/src/test/scala/org/apache/daffodil/dsom/walker/BasicWalker.scala ########## @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package org.apache.daffodil.dsom.walker + +import scala.collection.mutable.ArrayBuffer + +class BasicWalker(ignoreTypeWrappers: Boolean = false, onlyElements: Boolean = false) extends AbstractDSOMWalker { + + var nodeArr: ArrayBuffer[Either[TermView, TypeView]] = ArrayBuffer() + + override protected def onWalkBegin(root: RootView): Unit = {} + + override protected def onWalkEnd(root: RootView): Unit = {} + + override def onTermBegin(termElement: TermView): Unit = { + if (onlyElements) { + termElement match { + case _: ElementBaseView => nodeArr += Left(termElement) + case _ => + } + } else { + nodeArr += Left(termElement) + } + } + + override def onTermEnd(termElement: TermView): Unit = {} + + override def onTypeBegin(typeElement: TypeView): Unit = { + if (!ignoreTypeWrappers) { + nodeArr += Right(typeElement) + } + } + + override def onTypeEnd(typeElement: TypeView): Unit = {} +} Review comment: That makes sense, I did overlook that. In the latest revision I wound up simply adding the element both when the begin and end events are invoked, and then the refactored test for complex types verifies the elements corresponding to those end events occur in the expected indices in the list. I wound up just merging these extra assertions with the existing test for complex types - let me know if you think there should be an explicit separate test focused on pairs of start and end events. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
