Skip to content

Commit

Permalink
Add more tests for PrettyPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawley committed Jul 16, 2018
1 parent c47ce9e commit 8833418
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion jvm/src/test/scala/scala/xml/XMLTest.scala
Expand Up @@ -754,16 +754,64 @@ class XMLTestJVM {
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <a b="c"/>
val formatted = pp.format(x)
val expected =
"""|<a
|b="c"/>
|""".stripMargin
assertEquals(x, XML.loadString(formatted))
assertTrue(formatted.trim.lines.length >= 2)
assertEquals(expected, formatted)
}

@UnitTest
def issue231_withoutAttributes: Unit = {
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <abcdefg/>
val expected =
"""|<abcdefg/>
|""".stripMargin
val formatted = pp.format(x)
assertEquals(x, XML.loadString(formatted))
assertEquals(expected, formatted)
}

@UnitTest
def issue231_children: Unit = {
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <a b="c"><d/><e><f g="h"></f><i/></e></a>
val formatted = pp.format(x)
val expected =
"""|<a
|b="c">
| <d
| />
| <e>
| <f
| g="h"/>
| <i
| />
| </e>
|</a>
|""".stripMargin
assertEquals(expected, formatted)
}

@UnitTest
def issue231_elementText: Unit = {
val pp = new xml.PrettyPrinter(4, 2, minimizeEmpty = true)
val x = <a>x<b/><c>y</c><d/></a>
val formatted = pp.format(x)
val expected =
"""|<a>
| x
| <b
| />
| <c>
| y
| </c>
| <d
| />
|</a>""".stripMargin
assertEquals(expected, formatted)
}

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

0 comments on commit 8833418

Please sign in to comment.