From 72b11f64e6ca285a830e8a7b56f34d7110f8ed53 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Tue, 4 Aug 2015 00:58:05 -0400 Subject: [PATCH] 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) + } + +}