Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added new tests

  • Loading branch information...
commit 67e09f8b8646258d4f9989a61fe5e7107604653f 1 parent 87891d5
Anton Kazennikov kzn authored

Showing 1 changed file with 11 additions and 38 deletions. Show diff stats Hide diff stats

  1. +11 38 src/test/java/org/jsoup/select/SelectorNGTest.java
49 src/test/java/org/jsoup/select/SelectorNGTest.java
@@ -7,7 +7,6 @@
7 7 import org.jsoup.Jsoup;
8 8 import org.jsoup.nodes.Document;
9 9 import org.jsoup.nodes.Evaluator;
10   -import org.jsoup.select.ng.AndSelector;
11 10 import org.jsoup.select.ng.BasicSelector;
12 11 import org.jsoup.select.ng.ElementSelector;
13 12 import org.jsoup.select.ng.ParentSelector;
@@ -190,62 +189,36 @@ public void testGroupOr() {
190 189 assertEquals("span", els.get(4).tagName());
191 190 }
192 191
193   - /*@Test public void testGroupOrAttribute() {
194   - String h = "<div id=1 /><div id=2 /><div title=foo /><div title=bar />";
195   - Elements els = Jsoup.parse(h).select("[id],[title=foo]");
196   -
197   - assertEquals(3, els.size());
198   - assertEquals("1", els.get(0).id());
199   - assertEquals("2", els.get(1).id());
200   - assertEquals("foo", els.get(2).attr("title"));
201   - }
202   -
203   - @Test public void descendant() {
  192 + @Test
  193 + public void testDescendant() {
204 194 String h = "<div class=head><p class=first>Hello</p><p>There</p></div><p>None</p>";
205 195 Document doc = Jsoup.parse(h);
206   - Elements els = doc.select(".head p");
  196 + Elements els = SelectMatch.match(doc, new Evaluator.Tag("p"), new ParentSelector(new Evaluator.Class("head"))); //".head p"
207 197 assertEquals(2, els.size());
208 198 assertEquals("Hello", els.get(0).text());
209 199 assertEquals("There", els.get(1).text());
210 200
211   - Elements p = doc.select("p.first");
  201 + Elements p = SelectMatch.match(doc, new ElementSelector("p", "first", null)); //"p.first"
212 202 assertEquals(1, p.size());
213 203 assertEquals("Hello", p.get(0).text());
214 204
215   - Elements empty = doc.select("p .first"); // self, not descend, should not match
  205 + Elements empty = SelectMatch.match(doc, new Evaluator.Class("first"), new ParentSelector(new Evaluator.Tag("p")));// "p .first" self, not descend, should not match
216 206 assertEquals(0, empty.size());
217 207 }
218 208
219   - @Test public void and() {
220   - String h = "<div id=1 class='foo bar' title=bar name=qux><p class=foo title=bar>Hello</p></div";
221   - Document doc = Jsoup.parse(h);
222   -
223   - Elements div = doc.select("div.foo");
224   - assertEquals(1, div.size());
225   - assertEquals("div", div.first().tagName());
226   -
227   - Elements p = doc.select("div .foo"); // space indicates like "div *.foo"
228   - assertEquals(1, p.size());
229   - assertEquals("p", p.first().tagName());
230   -
231   - Elements div2 = doc.select("div#1.foo.bar[title=bar][name=qux]"); // very specific!
232   - assertEquals(1, div2.size());
233   - assertEquals("div", div2.first().tagName());
234   -
235   - Elements p2 = doc.select("div *.foo"); // space indicates like "div *.foo"
236   - assertEquals(1, p2.size());
237   - assertEquals("p", p2.first().tagName());
238   - }
239 209
240   - @Test public void deeperDescendant() {
  210 + @Test
  211 + public void testDeeperDescendant() {
241 212 String h = "<div class=head><p><span class=first>Hello</div><div class=head><p class=first><span>Another</span><p>Again</div>";
242   - Elements els = Jsoup.parse(h).select("div p .first");
  213 + Elements els = SelectMatch.match(Jsoup.parse(h), new Evaluator.Class("first"),
  214 +
  215 + new ParentSelector(BasicSelector.and(new Evaluator.Tag("p"), new ParentSelector(new Evaluator.Tag("div"))))); //"div p .first"
243 216 assertEquals(1, els.size());
244 217 assertEquals("Hello", els.first().text());
245 218 assertEquals("span", els.first().tagName());
246 219 }
247 220
248   - @Test public void parentChildElement() {
  221 + /*@Test public void parentChildElement() {
249 222 String h = "<div id=1><div id=2><div id = 3></div></div></div><div id=4></div>";
250 223 Document doc = Jsoup.parse(h);
251 224

0 comments on commit 67e09f8

Please sign in to comment.
Something went wrong with that request. Please try again.