From a50eca62ab4a24ffb7cd63f17a1307133448205c Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Fri, 23 Jan 2015 15:19:14 -0500 Subject: [PATCH 1/3] Unit test for #46 preserve short/self-closing/empty tags --- jvm/src/test/scala/scala/xml/XMLTest.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index cc40e998e..b937069f1 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -542,4 +542,17 @@ class XMLTestJVM { pp.format(x, sb) assertEquals(expected, sb.toString) } + + @UnitTest + def issue46: Unit = { + // val x = + val x = + // val x = Elem(null, "node", e, sc) + val pp = new xml.PrettyPrinter(80, 2) + // This assertion passed + assertEquals("", x.toString) + // This was the bug, producing + assertEquals("", pp.format(x.copy(minimizeEmpty = true))) + } + } From 063ab3b47e81a4547395aec6ac6f80c3936a2cf9 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Tue, 9 Feb 2016 19:04:09 -0500 Subject: [PATCH 2/3] Add new config for PrettyPrinter to minimize empty tags #90 * src/main/scala/scala/xml/PrettyPrinter.scala (PrettyPrinter): New parameter minimizeEmpty. (PrettyPrinter.traverse): Pass config for minimizeTags to Utility.serialize(). * src/test/scala/scala/xml/UtilityTest.scala (issue90): New test. * src/test/scala/scala/xml/XMLTest.scala (issue90): New test. --- jvm/src/test/scala/scala/xml/XMLTest.scala | 7 +++++++ shared/src/main/scala/scala/xml/PrettyPrinter.scala | 5 +++-- shared/src/test/scala/scala/xml/UtilityTest.scala | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index b937069f1..5d90054c7 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -555,4 +555,11 @@ class XMLTestJVM { assertEquals("", pp.format(x.copy(minimizeEmpty = true))) } + @UnitTest + def issue90: Unit = { + val pp = new xml.PrettyPrinter(80, 2, minimizeEmpty = true) + val x = + assertEquals("\n \n", pp.format(x)) + } + } diff --git a/shared/src/main/scala/scala/xml/PrettyPrinter.scala b/shared/src/main/scala/scala/xml/PrettyPrinter.scala index b3f4f9940..85bad15be 100755 --- a/shared/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/shared/src/main/scala/scala/xml/PrettyPrinter.scala @@ -23,8 +23,9 @@ import Utility.sbToString * @param width the width to fit the output into * @param step indentation */ -class PrettyPrinter(width: Int, step: Int) { +class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean = false) { + val minimizeMode = if (minimizeEmpty) MinimizeMode.Always else MinimizeMode.Default class BrokenException() extends java.lang.Exception class Item @@ -150,7 +151,7 @@ class PrettyPrinter(width: Int, step: Int) { case _ => val test = { val sb = new StringBuilder() - Utility.serialize(node, pscope, sb, stripComments = false) + Utility.serialize(node, pscope, sb, stripComments = false, minimizeTags = minimizeMode) if (doPreserve(node)) sb.toString else TextBuffer.fromString(sb.toString).toText(0).data } diff --git a/shared/src/test/scala/scala/xml/UtilityTest.scala b/shared/src/test/scala/scala/xml/UtilityTest.scala index f6b3828fa..58aadf780 100644 --- a/shared/src/test/scala/scala/xml/UtilityTest.scala +++ b/shared/src/test/scala/scala/xml/UtilityTest.scala @@ -51,4 +51,10 @@ class UtilityTest { .hashCode // Bug #777 } + @Test + def issue90: Unit = { + val x = + assertEquals("", Utility.serialize(x, minimizeTags = MinimizeMode.Always).toString) + } + } From 8c44f6dc770c38f05a80cc64c7a1066204b1f757 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Tue, 9 Feb 2016 22:18:04 -0500 Subject: [PATCH 3/3] Fix Travis build failure from migration-manager (mimaReportBinaryIssues) * src/main/scala/scala/xml/PrettyPrinter.scala (PrettyPrinter): Convert class default parameter to alternate constructor. --- shared/src/main/scala/scala/xml/PrettyPrinter.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/scala/xml/PrettyPrinter.scala b/shared/src/main/scala/scala/xml/PrettyPrinter.scala index 85bad15be..2da75a160 100755 --- a/shared/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/shared/src/main/scala/scala/xml/PrettyPrinter.scala @@ -23,7 +23,9 @@ import Utility.sbToString * @param width the width to fit the output into * @param step indentation */ -class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean = false) { +class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) { + + def this(width: Int, step: Int) = this(width, step, minimizeEmpty = false) val minimizeMode = if (minimizeEmpty) MinimizeMode.Always else MinimizeMode.Default class BrokenException() extends java.lang.Exception