Closed hghina0 closed 5 years ago
Is it known issue?
No, probably not. You have come accross an unfortunate name-collision because of the lexical scoping rules of Scala. It's a sconsequence of this class member:
http://www.scala-lang.org/api/current/scala-xml/scala/xml/transform/RewriteRule.html#name:String
It's not clear what it's for, but there's probably no reason to have it there, IMO.
Here's a minimal version of your test
@Test
def rewriteRuleNameCollision = { // #129
val name = "contents"
val transformer = new RuleTransformer(new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case elem @ Elem(prefix, label, attribs, scope, _) if elem.label == name =>
Elem(prefix, label, attribs, scope, false, Text("2"))
case _ => n
}
})
assertEquals(<contents>2</contents>, transformer(<contents>1</contents>))
}
It fails with
[error] Test scala.xml.Transformers.rewriteRuleNameCollision failed: expected:<<contents>2</contents>> but was:<<contents>1</contents>>
Thanks for quick clarification. I appreciate.
Below program doesn't give expected output
If I change "case if" statement like
It transforms xml as expected. Is it known issue?