Search in sources :

Example 1 with BooleanAttribute

use of org.jsoup.nodes.BooleanAttribute in project jsoup by jhy.

the class AttributeParseTest method parsesBooleanAttributes.

@Test
public void parsesBooleanAttributes() {
    String html = "<a normal=\"123\" boolean empty=\"\"></a>";
    Element el = Jsoup.parse(html).select("a").first();
    assertEquals("123", el.attr("normal"));
    assertEquals("", el.attr("boolean"));
    assertEquals("", el.attr("empty"));
    List<Attribute> attributes = el.attributes().asList();
    assertEquals("There should be 3 attribute present", 3, attributes.size());
    // Assuming the list order always follows the parsed html
    assertFalse("'normal' attribute should not be boolean", attributes.get(0) instanceof BooleanAttribute);
    assertTrue("'boolean' attribute should be boolean", attributes.get(1) instanceof BooleanAttribute);
    assertFalse("'empty' attribute should not be boolean", attributes.get(2) instanceof BooleanAttribute);
    assertEquals(html, el.outerHtml());
}
Also used : BooleanAttribute(org.jsoup.nodes.BooleanAttribute) Attribute(org.jsoup.nodes.Attribute) BooleanAttribute(org.jsoup.nodes.BooleanAttribute) Element(org.jsoup.nodes.Element) Test(org.junit.Test)

Aggregations

Attribute (org.jsoup.nodes.Attribute)1 BooleanAttribute (org.jsoup.nodes.BooleanAttribute)1 Element (org.jsoup.nodes.Element)1 Test (org.junit.Test)1