From 72b11f64e6ca285a830e8a7b56f34d7110f8ed53 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Tue, 4 Aug 2015 00:58:05 -0400 Subject: [PATCH 1/2] Add more XML attribute unit tests for SI-9047 --- src/test/scala/scala/xml/AttributeTest.scala | 71 +++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/src/test/scala/scala/xml/AttributeTest.scala b/src/test/scala/scala/xml/AttributeTest.scala index 13aa7bfc6..0018e0ee3 100644 --- a/src/test/scala/scala/xml/AttributeTest.scala +++ b/src/test/scala/scala/xml/AttributeTest.scala @@ -65,4 +65,73 @@ class AttributeTest { assertEquals("apple", xml \@ "bar") } -} \ No newline at end of file + @Test + def attributePathRootNoAttribute: Unit = { + val xml = + assertEquals(NodeSeq.Empty, xml \ "@bar") + } + + @Test(expected=classOf[IllegalArgumentException]) + def attributePathIllegalEmptyAttribute: Unit = { + val xml = + xml \ "@" + } + + @Test + def attributePathRootWithOneAttribute: Unit = { + val xml = + assertEquals(Group(Text("apple")), xml \ "@bar") + // assertEquals(NodeSeq.fromSeq(Seq(Text("apple"))), xml \ "@bar") + } + + @Test + def attributePathRootWithMissingAttributes: Unit = { + val xml = + assertEquals(NodeSeq.Empty, xml \ "@oops") + } + + @Test + def attributePathDuplicateAttribute: Unit = { + val xml = Elem(null, "foo", + Attribute("bar", Text("apple"), + Attribute("bar", Text("orange"), Null)), TopScope) + assertEquals(Group(Text("apple")), xml \ "@bar") + } + + @Test + def attributePathDescendantAttributes: Unit = { + val xml = + assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "@bar")) + } + + @Test(expected=classOf[IllegalArgumentException]) + def attributePathDescendantIllegalEmptyAttribute: Unit = { + val xml = + xml \\ "@" + } + + @Test + def attributePathNoDescendantAttributes: Unit = { + val xml = + assertEquals(NodeSeq.Empty, (xml \\ "@oops")) + } + + @Test + def attributePathOneChildWithAttributes: Unit = { + val xml = > + assertEquals(Group(Seq(Text("1"))), (xml \ "b" \ "@bar")) + } + + @Test + def attributePathTwoChildrenWithAttributes: Unit = { + val xml = + val b = xml \ "b" + assertEquals(2, b.length) + assertEquals(NodeSeq.fromSeq(Seq(, )), b) + val barFail = b \ "@bar" + val barList = b.map(_ \ "@bar") + assertEquals(NodeSeq.Empty, barFail) + assertEquals(List(Group(Seq(Text("1"))), Group(Seq(Text("2")))), barList) + } + +} From d5609e3b6b71b661303976ecf01c4611b81efdda Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Sun, 9 Aug 2015 23:35:47 -0400 Subject: [PATCH 2/2] Add descendant XML attribute unit tests --- src/test/scala/scala/xml/AttributeTest.scala | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/scala/scala/xml/AttributeTest.scala b/src/test/scala/scala/xml/AttributeTest.scala index 0018e0ee3..67b289748 100644 --- a/src/test/scala/scala/xml/AttributeTest.scala +++ b/src/test/scala/scala/xml/AttributeTest.scala @@ -104,6 +104,30 @@ class AttributeTest { assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "@bar")) } + @Test + def attributeDescendantPathChildAttributes: Unit = { + val xml = + assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \ "b" \\ "@bar")) + } + + @Test + def attributeDescendantPathDescendantAttributes: Unit = { + val xml = + assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "b" \\ "@bar")) + } + + @Test + def attributeChildDescendantPathDescendantAttributes: Unit = { + val xml = + assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \ "a" \\ "@bar")) + } + + @Test + def attributeDescendantDescendantPathDescendantAttributes: Unit = { + val xml = + assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "b" \\ "@bar")) + } + @Test(expected=classOf[IllegalArgumentException]) def attributePathDescendantIllegalEmptyAttribute: Unit = { val xml =