package us.codecraft.webmagic.selector;

import org.junit.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author code4crafter@gmail.com
 */
public class SelectorTest {

    private String html = "<div><a href='http://whatever.com/aaa'></a></div><div><a href='http://whatever.com/bbb'></a></div>";

    @Test
    public void testChain() throws Exception {
        Html selectable = new Html(html);
        List<String> linksWithoutChain = selectable.links().all();
        Selectable xpath = selectable.xpath("//div");
        List<String> linksWithChainFirstCall = xpath.links().all();
        List<String> linksWithChainSecondCall = xpath.links().all();
        assertThat(linksWithoutChain).hasSameSizeAs(linksWithChainFirstCall);
        assertThat(linksWithChainFirstCall).hasSameSizeAs(linksWithChainSecondCall);
    }

    @Test
    public void testNodes() throws Exception {
        Html selectable = new Html(html);
List<Selectable> divs = html.xpath("//div").nodes();
for (Selectable div : divs) {
    System.out.println(div.xpath("//h2").get());
}

        assertThat(links.get(0).links().get()).isEqualTo("http://whatever.com/aaa");
    }
}

@@ -967,16 +967,24 @@
 (html);%0A
+        
 List%3CSel
@@ -996,100 +996,26 @@
 le%3E 
-divs = html.xpath(%22//div%22).nodes();%0Afor (Selectable div : divs) %7B%0A    System.out.println(div
+links = selectable
 .xpa
@@ -1024,23 +1024,20 @@
 (%22//
-h2%22).get());%0A%7D%0A
+a%22).nodes();
 %0A   

fix test