@@ -117,6 +117,18 @@ public class ElementTest {
117
117
assertEquals ("element" , p .lastElementSibling ().text ());
118
118
}
119
119
120
+ @ Test public void testGetSiblingsWithDuplicateContent () {
121
+ Document doc = Jsoup .parse ("<div><p>Hello<p id=1>there<p>this<p>this<p>is<p>an<p id=last>element</div>" );
122
+ Element p = doc .getElementById ("1" );
123
+ assertEquals ("there" , p .text ());
124
+ assertEquals ("Hello" , p .previousElementSibling ().text ());
125
+ assertEquals ("this" , p .nextElementSibling ().text ());
126
+ assertEquals ("this" , p .nextElementSibling ().nextElementSibling ().text ());
127
+ assertEquals ("is" , p .nextElementSibling ().nextElementSibling ().nextElementSibling ().text ());
128
+ assertEquals ("Hello" , p .firstElementSibling ().text ());
129
+ assertEquals ("element" , p .lastElementSibling ().text ());
130
+ }
131
+
120
132
@ Test public void testGetParents () {
121
133
Document doc = Jsoup .parse ("<div><p>Hello <span>there</span></div>" );
122
134
Element span = doc .select ("span" ).first ();
@@ -137,6 +149,14 @@ public class ElementTest {
137
149
assertTrue (2 == ps .get (2 ).elementSiblingIndex ());
138
150
}
139
151
152
+ @ Test public void testElementSiblingIndexSameContent () {
153
+ Document doc = Jsoup .parse ("<div><p>One</p>...<p>One</p>...<p>One</p>" );
154
+ Elements ps = doc .select ("p" );
155
+ assertTrue (0 == ps .get (0 ).elementSiblingIndex ());
156
+ assertTrue (1 == ps .get (1 ).elementSiblingIndex ());
157
+ assertTrue (2 == ps .get (2 ).elementSiblingIndex ());
158
+ }
159
+
140
160
@ Test public void testGetElementsWithClass () {
141
161
Document doc = Jsoup .parse ("<div class='mellow yellow'><span class=mellow>Hello <b class='yellow'>Yellow!</b></span><p>Empty</p></div>" );
142
162
0 commit comments