Skip to content

Commit c9601c3

Browse files
committed
Unit tests for scala#65 XML attributes parsed in reverse order
1 parent 3161a38 commit c9601c3

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/test/scala/scala/xml/AttributeTest.scala

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.junit.runners.JUnit4
77
import org.junit.Assert.assertTrue
88
import org.junit.Assert.assertFalse
99
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertNotEquals
1011

1112
class AttributeTest {
1213
@Test
@@ -52,6 +53,35 @@ class AttributeTest {
5253
assertEquals(None, z.get("foo"))
5354
}
5455

56+
@Test
57+
def attributeOrder: Unit = {
58+
val x = <x y="1" z="2"/>
59+
assertEquals(<x y="1" z="2"/>, x.toString)
60+
}
61+
62+
@Test
63+
def attributesFromString: Unit = {
64+
val input = """<x y="1" z="2"/>"""
65+
val doc = XML.loadString(input)
66+
assertEquals(input, doc.toString)
67+
}
68+
69+
@Test
70+
def attributesAndNamespaceFromString: Unit = {
71+
val input = """<x xmlns:w="w" y="1" z="2"/>"""
72+
val doc = XML.loadString(input)
73+
assertNotEquals(input, doc.toString)
74+
val input2 = """<x y="1" z="2" xmlns:w="w"/>"""
75+
val doc2 = XML.loadString(input2)
76+
assertEquals(input2, doc2.toString)
77+
}
78+
79+
@Test(expected=classOf[SAXParseException])
80+
def attributesFromStringWithDuplicate: Unit = {
81+
val input = """<elem one="test" one="test1" two="test2" three="test3"></elem>"""
82+
val doc = XML.loadString(input)
83+
}
84+
5585
@Test
5686
def attributeToString: Unit = {
5787
val expected: String = """<b x="&amp;"/>"""

src/test/scala/scala/xml/UtilityTest.scala

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class UtilityTest {
4040

4141
@Test
4242
def sort: Unit = {
43+
assertEquals("", xml.Utility.sort(<a/>.attributes).toString)
44+
assertEquals(""" b="c"""", xml.Utility.sort(<a b="c"/>.attributes).toString)
4345
val q = xml.Utility.sort(<a g='3' j='2' oo='2' a='2'/>)
4446
assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString)
4547
val pp = new xml.PrettyPrinter(80,5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package scala.xml.parsing
2+
3+
import scala.xml.XML
4+
import scala.xml.PrettyPrinter
5+
6+
import org.junit.Test
7+
import org.junit.Ignore
8+
import org.junit.runner.RunWith
9+
import org.junit.runners.JUnit4
10+
import org.junit.Assert.assertEquals
11+
12+
class ConstructingParserTest {
13+
14+
@Test
15+
def SI6341issue65: Unit = {
16+
val input = """<elem one="test" two="test2" three="test3"/>"""
17+
val cpa = ConstructingParser.fromSource(io.Source.fromString(input), preserveWS = true)
18+
val cpadoc = cpa.document()
19+
val ppr = new PrettyPrinter(80,5)
20+
val out = ppr.format(cpadoc.docElem)
21+
assertEquals(input, out)
22+
}
23+
24+
}

0 commit comments

Comments
 (0)