summaryrefslogtreecommitdiff
path: root/test/files/run/bug2364.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-11 17:16:56 +0000
committerPaul Phillips <paulp@improving.org>2010-01-11 17:16:56 +0000
commitc6c3b44b0c4e019b9e65a88300c89f7e617ad56c (patch)
tree206a5fbb4e013fe0bc1c250d0f6888759605d0b0 /test/files/run/bug2364.scala
parent91e88b3f7d4a2765c11bf4ac5495eb7c329bc18e (diff)
downloadscala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.tar.gz
scala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.tar.bz2
scala-c6c3b44b0c4e019b9e65a88300c89f7e617ad56c.zip
Fix and test case for #2364, which regressed wi...
Fix and test case for #2364, which regressed with the fix to #2721.
Diffstat (limited to 'test/files/run/bug2364.scala')
-rw-r--r--test/files/run/bug2364.scala57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/files/run/bug2364.scala b/test/files/run/bug2364.scala
new file mode 100644
index 0000000000..0d1600c048
--- /dev/null
+++ b/test/files/run/bug2364.scala
@@ -0,0 +1,57 @@
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
+import com.sun.xml.internal.fastinfoset._
+import com.sun.xml.internal.fastinfoset.sax._
+import scala.xml.parsing.NoBindingFactoryAdapter
+import scala.xml._
+
+object Test {
+ def main(args: Array[String]) {
+ val node = <test/>
+ val bytes = new ByteArrayOutputStream
+ val serializer = new SAXDocumentSerializer()
+
+ serializer.setOutputStream(bytes)
+ serializer.startDocument()
+ serialize(node, serializer)
+ serializer.endDocument()
+ println(parse(new ByteArrayInputStream(bytes.toByteArray)))
+ }
+ def serialize(node: Node, serializer: SAXDocumentSerializer) {
+ node match {
+ case _ : ProcInstr | _ : Comment | _ : EntityRef =>
+ case x : Atom[_] =>
+ val chars = x.text.toCharArray
+ serializer.characters(chars, 0, chars.length)
+ case _ : Elem =>
+ serializer.startElement("", node.label.toLowerCase, node.label.toLowerCase, attributes(node.attributes))
+ for (m <- node.child) serialize(m, serializer)
+ serializer.endElement("", node.label.toLowerCase, node.label.toLowerCase)
+ }
+ }
+ def parse(str: ByteArrayInputStream) = {
+ val parser = new SAXDocumentParser
+ val fac = new NoBindingFactoryAdapter
+
+ parser.setContentHandler(fac)
+ try {
+ parser.parse(str)
+ } catch {
+ case x: Exception =>
+ x.printStackTrace
+ }
+ fac.rootElem
+ }
+ def attributes(d: MetaData) = {
+ val attrs = new AttributesHolder
+
+ if (d != null) {
+ for (attr <- d) {
+ val sb = new StringBuilder()
+ Utility.sequenceToXML(attr.value, TopScope, sb, true)
+ attrs.addAttribute(new QualifiedName("", "", attr.key.toLowerCase), sb.toString)
+ }
+ }
+ attrs
+ }
+}