-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more XML attribute unit tests for SI-9047 #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,97 @@ class AttributeTest { | |
assertEquals("apple", xml \@ "bar") | ||
} | ||
|
||
} | ||
@Test | ||
def attributePathRootNoAttribute: Unit = { | ||
val xml = <foo /> | ||
assertEquals(NodeSeq.Empty, xml \ "@bar") | ||
} | ||
|
||
@Test(expected=classOf[IllegalArgumentException]) | ||
def attributePathIllegalEmptyAttribute: Unit = { | ||
val xml = <foo /> | ||
xml \ "@" | ||
} | ||
|
||
@Test | ||
def attributePathRootWithOneAttribute: Unit = { | ||
val xml = <foo bar="apple" /> | ||
assertEquals(Group(Text("apple")), xml \ "@bar") | ||
// assertEquals(NodeSeq.fromSeq(Seq(Text("apple"))), xml \ "@bar") | ||
} | ||
|
||
@Test | ||
def attributePathRootWithMissingAttributes: Unit = { | ||
val xml = <foo bar="apple" /> | ||
assertEquals(NodeSeq.Empty, xml \ "@oops") | ||
} | ||
|
||
@Test | ||
def attributePathDuplicateAttribute: Unit = { | ||
val xml = Elem(null, "foo", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reasons you are not using xml literals in this unit test ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using xml literals where I can. This particular unit test doesn't because you can't: The literal syntax won't let you actually create an element with duplicate attributes. I'm trying to force it by manually constructing a |
||
Attribute("bar", Text("apple"), | ||
Attribute("bar", Text("orange"), Null)), TopScope) | ||
assertEquals(Group(Text("apple")), xml \ "@bar") | ||
} | ||
|
||
@Test | ||
def attributePathDescendantAttributes: Unit = { | ||
val xml = <a><b bar="1" /><b bar="2" /></a> | ||
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "@bar")) | ||
} | ||
|
||
@Test | ||
def attributeDescendantPathChildAttributes: Unit = { | ||
val xml = <a><b bar="1" /><b bar="2" /></a> | ||
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \ "b" \\ "@bar")) | ||
} | ||
|
||
@Test | ||
def attributeDescendantPathDescendantAttributes: Unit = { | ||
val xml = <a><b bar="1" /><b bar="2" /></a> | ||
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "b" \\ "@bar")) | ||
} | ||
|
||
@Test | ||
def attributeChildDescendantPathDescendantAttributes: Unit = { | ||
val xml = <x><a><b bar="1" /><b bar="2" /></a></x> | ||
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \ "a" \\ "@bar")) | ||
} | ||
|
||
@Test | ||
def attributeDescendantDescendantPathDescendantAttributes: Unit = { | ||
val xml = <x><a><b bar="1" /><b bar="2" /></a></x> | ||
assertEquals(NodeSeq.fromSeq(Seq(Text("1"), Text("2"))), (xml \\ "b" \\ "@bar")) | ||
} | ||
|
||
@Test(expected=classOf[IllegalArgumentException]) | ||
def attributePathDescendantIllegalEmptyAttribute: Unit = { | ||
val xml = <foo /> | ||
xml \\ "@" | ||
} | ||
|
||
@Test | ||
def attributePathNoDescendantAttributes: Unit = { | ||
val xml = <a><b bar="1" /><b bar="2" /></a> | ||
assertEquals(NodeSeq.Empty, (xml \\ "@oops")) | ||
} | ||
|
||
@Test | ||
def attributePathOneChildWithAttributes: Unit = { | ||
val xml = <a><b bar="1" />></a> | ||
assertEquals(Group(Seq(Text("1"))), (xml \ "b" \ "@bar")) | ||
} | ||
|
||
@Test | ||
def attributePathTwoChildrenWithAttributes: Unit = { | ||
val xml = <a><b bar="1" /><b bar="2" /></a> | ||
val b = xml \ "b" | ||
assertEquals(2, b.length) | ||
assertEquals(NodeSeq.fromSeq(Seq(<b bar="1"/>, <b bar="2"/>)), 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) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we get rid of this comment ? Advance sorries if it feels very nit picky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Looks like I put that there on purpose. It is what the test would be if we used the proposed change in issue 43. Granted, I didn't leave these comments consistently.