Skip to content

Commit 372cd83

Browse files
authored
Merge pull request #240 from ashawley/issue231-tests
Add more tests for PrettyPrinter
2 parents c47ce9e + 8833418 commit 372cd83

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

jvm/src/test/scala/scala/xml/XMLTest.scala

+49-1
Original file line numberDiff line numberDiff line change
@@ -754,16 +754,64 @@ class XMLTestJVM {
754754
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
755755
val x = <a b="c"/>
756756
val formatted = pp.format(x)
757+
val expected =
758+
"""|<a
759+
|b="c"/>
760+
|""".stripMargin
757761
assertEquals(x, XML.loadString(formatted))
758-
assertTrue(formatted.trim.lines.length >= 2)
762+
assertEquals(expected, formatted)
759763
}
760764

761765
@UnitTest
762766
def issue231_withoutAttributes: Unit = {
763767
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
764768
val x = <abcdefg/>
769+
val expected =
770+
"""|<abcdefg/>
771+
|""".stripMargin
765772
val formatted = pp.format(x)
766773
assertEquals(x, XML.loadString(formatted))
774+
assertEquals(expected, formatted)
775+
}
776+
777+
@UnitTest
778+
def issue231_children: Unit = {
779+
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
780+
val x = <a b="c"><d/><e><f g="h"></f><i/></e></a>
781+
val formatted = pp.format(x)
782+
val expected =
783+
"""|<a
784+
|b="c">
785+
| <d
786+
| />
787+
| <e>
788+
| <f
789+
| g="h"/>
790+
| <i
791+
| />
792+
| </e>
793+
|</a>
794+
|""".stripMargin
795+
assertEquals(expected, formatted)
796+
}
797+
798+
@UnitTest
799+
def issue231_elementText: Unit = {
800+
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
801+
val x = <a>x<b/><c>y</c><d/></a>
802+
val formatted = pp.format(x)
803+
val expected =
804+
"""|<a>
805+
| x
806+
| <b
807+
| />
808+
| <c>
809+
| y
810+
| </c>
811+
| <d
812+
| />
813+
|</a>""".stripMargin
814+
assertEquals(expected, formatted)
767815
}
768816

769817
def toSource(s: String) = new scala.io.Source {

0 commit comments

Comments
 (0)