Skip to content

Commit

Permalink
Unit tests for scala#65 XML attributes parsed in reverse order
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawley committed Sep 17, 2015
1 parent 3161a38 commit c9601c3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/scala/scala/xml/AttributeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.junit.runners.JUnit4
import org.junit.Assert.assertTrue
import org.junit.Assert.assertFalse
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals

class AttributeTest {
@Test
Expand Down Expand Up @@ -52,6 +53,35 @@ class AttributeTest {
assertEquals(None, z.get("foo"))
}

@Test
def attributeOrder: Unit = {
val x = <x y="1" z="2"/>
assertEquals(<x y="1" z="2"/>, x.toString)
}

@Test
def attributesFromString: Unit = {
val input = """<x y="1" z="2"/>"""
val doc = XML.loadString(input)
assertEquals(input, doc.toString)
}

@Test
def attributesAndNamespaceFromString: Unit = {
val input = """<x xmlns:w="w" y="1" z="2"/>"""
val doc = XML.loadString(input)
assertNotEquals(input, doc.toString)
val input2 = """<x y="1" z="2" xmlns:w="w"/>"""
val doc2 = XML.loadString(input2)
assertEquals(input2, doc2.toString)
}

@Test(expected=classOf[SAXParseException])
def attributesFromStringWithDuplicate: Unit = {
val input = """<elem one="test" one="test1" two="test2" three="test3"></elem>"""
val doc = XML.loadString(input)
}

@Test
def attributeToString: Unit = {
val expected: String = """<b x="&amp;"/>"""
Expand Down
2 changes: 2 additions & 0 deletions src/test/scala/scala/xml/UtilityTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class UtilityTest {

@Test
def sort: Unit = {
assertEquals("", xml.Utility.sort(<a/>.attributes).toString)
assertEquals(""" b="c"""", xml.Utility.sort(<a b="c"/>.attributes).toString)
val q = xml.Utility.sort(<a g='3' j='2' oo='2' a='2'/>)
assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString)
val pp = new xml.PrettyPrinter(80,5)
Expand Down
24 changes: 24 additions & 0 deletions src/test/scala/scala/xml/parsing/ConstructingParserTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package scala.xml.parsing

import scala.xml.XML
import scala.xml.PrettyPrinter

import org.junit.Test
import org.junit.Ignore
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Assert.assertEquals

class ConstructingParserTest {

@Test
def SI6341issue65: Unit = {
val input = """<elem one="test" two="test2" three="test3"/>"""
val cpa = ConstructingParser.fromSource(io.Source.fromString(input), preserveWS = true)
val cpadoc = cpa.document()
val ppr = new PrettyPrinter(80,5)
val out = ppr.format(cpadoc.docElem)
assertEquals(input, out)
}

}

0 comments on commit c9601c3

Please sign in to comment.