From 4c3b8a2181dc52462d9c8a492505e85a4fbdddab Mon Sep 17 00:00:00 2001 From: Chris Loy Date: Sat, 11 Apr 2015 11:41:01 +0100 Subject: [PATCH 1/2] Default to TopScope when formatting multiple nodes --- src/main/scala/scala/xml/PrettyPrinter.scala | 2 +- src/test/scala/scala/xml/XMLTest.scala | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/scala/scala/xml/PrettyPrinter.scala b/src/main/scala/scala/xml/PrettyPrinter.scala index a175f1df2..99a0e4a36 100755 --- a/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/src/main/scala/scala/xml/PrettyPrinter.scala @@ -253,7 +253,7 @@ class PrettyPrinter(width: Int, step: Int) { * @param nodes the sequence of nodes to be serialized * @param pscope the namespace to prefix mapping */ - def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = null): String = + def formatNodes(nodes: Seq[Node], pscope: NamespaceBinding = TopScope): String = sbToString(formatNodes(nodes, pscope, _)) /** diff --git a/src/test/scala/scala/xml/XMLTest.scala b/src/test/scala/scala/xml/XMLTest.scala index 01431baf1..380a39dbf 100644 --- a/src/test/scala/scala/xml/XMLTest.scala +++ b/src/test/scala/scala/xml/XMLTest.scala @@ -836,4 +836,14 @@ expected closing tag of foo assertEquals("""""", pp.format(x)) } + @UnitTest + def nodeSeqNs: Unit = { + val x = { + + } + val pp = new PrettyPrinter(80, 2) + val expected = """""" + assertEquals(expected, pp.formatNodes(x)) + } + } From 7243aa08f590d52efaf80ab2313e3cbc443e45bb Mon Sep 17 00:00:00 2001 From: Chris Loy Date: Mon, 13 Apr 2015 23:29:54 +0100 Subject: [PATCH 2/2] Default to TopScope if printing with StringBuilder --- src/main/scala/scala/xml/PrettyPrinter.scala | 2 +- src/test/scala/scala/xml/XMLTest.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/scala/scala/xml/PrettyPrinter.scala b/src/main/scala/scala/xml/PrettyPrinter.scala index 99a0e4a36..4f1024e1a 100755 --- a/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/src/main/scala/scala/xml/PrettyPrinter.scala @@ -203,7 +203,7 @@ class PrettyPrinter(width: Int, step: Int) { * @param sb the stringbuffer to append to */ def format(n: Node, sb: StringBuilder) { // entry point - format(n, null, sb) + format(n, TopScope, sb) } def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder) { // entry point diff --git a/src/test/scala/scala/xml/XMLTest.scala b/src/test/scala/scala/xml/XMLTest.scala index 380a39dbf..23c143396 100644 --- a/src/test/scala/scala/xml/XMLTest.scala +++ b/src/test/scala/scala/xml/XMLTest.scala @@ -846,4 +846,15 @@ expected closing tag of foo assertEquals(expected, pp.formatNodes(x)) } + @UnitTest + def nodeStringBuilder: Unit = { + val x = { + + } + val pp = new PrettyPrinter(80, 2) + val expected = """""" + val sb = new StringBuilder + pp.format(x, sb) + assertEquals(expected, sb.toString) + } }