@@ -65,4 +65,73 @@ class AttributeTest {
6565 assertEquals(" apple" , xml \@ " bar" )
6666 }
6767
68- }
68+ @ Test
69+ def attributePathRootNoAttribute : Unit = {
70+ val xml = <foo />
71+ assertEquals(NodeSeq .Empty , xml \ " @bar" )
72+ }
73+
74+ @ Test (expected= classOf [IllegalArgumentException ])
75+ def attributePathIllegalEmptyAttribute : Unit = {
76+ val xml = <foo />
77+ xml \ " @"
78+ }
79+
80+ @ Test
81+ def attributePathRootWithOneAttribute : Unit = {
82+ val xml = <foo bar =" apple" />
83+ assertEquals(Group (Text (" apple" )), xml \ " @bar" )
84+ // assertEquals(NodeSeq.fromSeq(Seq(Text("apple"))), xml \ "@bar")
85+ }
86+
87+ @ Test
88+ def attributePathRootWithMissingAttributes : Unit = {
89+ val xml = <foo bar =" apple" />
90+ assertEquals(NodeSeq .Empty , xml \ " @oops" )
91+ }
92+
93+ @ Test
94+ def attributePathDuplicateAttribute : Unit = {
95+ val xml = Elem (null , " foo" ,
96+ Attribute (" bar" , Text (" apple" ),
97+ Attribute (" bar" , Text (" orange" ), Null )), TopScope )
98+ assertEquals(Group (Text (" apple" )), xml \ " @bar" )
99+ }
100+
101+ @ Test
102+ def attributePathDescendantAttributes : Unit = {
103+ val xml = <a ><b bar =" 1" /><b bar =" 2" /></a >
104+ assertEquals(NodeSeq .fromSeq(Seq (Text (" 1" ), Text (" 2" ))), (xml \\ " @bar" ))
105+ }
106+
107+ @ Test (expected= classOf [IllegalArgumentException ])
108+ def attributePathDescendantIllegalEmptyAttribute : Unit = {
109+ val xml = <foo />
110+ xml \\ " @"
111+ }
112+
113+ @ Test
114+ def attributePathNoDescendantAttributes : Unit = {
115+ val xml = <a ><b bar =" 1" /><b bar =" 2" /></a >
116+ assertEquals(NodeSeq .Empty , (xml \\ " @oops" ))
117+ }
118+
119+ @ Test
120+ def attributePathOneChildWithAttributes : Unit = {
121+ val xml = <a ><b bar =" 1" />></ a>
122+ assertEquals(Group (Seq (Text (" 1" ))), (xml \ " b" \ " @bar" ))
123+ }
124+
125+ @ Test
126+ def attributePathTwoChildrenWithAttributes : Unit = {
127+ val xml = <a ><b bar =" 1" /><b bar =" 2" /></a >
128+ val b = xml \ " b"
129+ assertEquals(2 , b.length)
130+ assertEquals(NodeSeq .fromSeq(Seq (<b bar =" 1" />, <b bar =" 2" />)), b)
131+ val barFail = b \ " @bar"
132+ val barList = b.map(_ \ " @bar" )
133+ assertEquals(NodeSeq .Empty , barFail)
134+ assertEquals(List (Group (Seq (Text (" 1" ))), Group (Seq (Text (" 2" )))), barList)
135+ }
136+
137+ }
0 commit comments