From aff8702049244990befd3b8f37270e6657b5d786 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Thu, 17 Sep 2015 11:22:12 -0400 Subject: [PATCH] Unit tests for #65 XML attributes parsed in reverse order --- src/test/scala/scala/xml/AttributeTest.scala | 30 +++++++++++++++++++ src/test/scala/scala/xml/UtilityTest.scala | 2 ++ .../xml/parsing/ConstructingParserTest.scala | 24 +++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/test/scala/scala/xml/parsing/ConstructingParserTest.scala diff --git a/src/test/scala/scala/xml/AttributeTest.scala b/src/test/scala/scala/xml/AttributeTest.scala index 67b289748..274f9fdd1 100644 --- a/src/test/scala/scala/xml/AttributeTest.scala +++ b/src/test/scala/scala/xml/AttributeTest.scala @@ -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 @@ -52,6 +53,35 @@ class AttributeTest { assertEquals(None, z.get("foo")) } + @Test + def attributeOrder: Unit = { + val x = + assertEquals("""""", x.toString) + } + + @Test + def attributesFromString: Unit = { + val input = """""" + val doc = XML.loadString(input) + assertEquals(input, doc.toString) + } + + @Test + def attributesAndNamespaceFromString: Unit = { + val input = """""" + val doc = XML.loadString(input) + assertNotEquals(input, doc.toString) + val input2 = """""" + val doc2 = XML.loadString(input2) + assertEquals(input2, doc2.toString) + } + + @Test(expected=classOf[SAXParseException]) + def attributesFromStringWithDuplicate: Unit = { + val input = """""" + val doc = XML.loadString(input) + } + @Test def attributeToString: Unit = { val expected: String = """""" diff --git a/src/test/scala/scala/xml/UtilityTest.scala b/src/test/scala/scala/xml/UtilityTest.scala index eba631efb..b7cffc235 100644 --- a/src/test/scala/scala/xml/UtilityTest.scala +++ b/src/test/scala/scala/xml/UtilityTest.scala @@ -40,6 +40,8 @@ class UtilityTest { @Test def sort: Unit = { + assertEquals("", xml.Utility.sort(.attributes).toString) + assertEquals(""" b="c"""", xml.Utility.sort(.attributes).toString) val q = xml.Utility.sort() assertEquals(" a=\"2\" g=\"3\" j=\"2\" oo=\"2\"", xml.Utility.sort(q.attributes).toString) val pp = new xml.PrettyPrinter(80,5) diff --git a/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala b/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala new file mode 100644 index 000000000..b00639cbf --- /dev/null +++ b/src/test/scala/scala/xml/parsing/ConstructingParserTest.scala @@ -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 = """""" + 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) + } + +}