Skip to content

Commit

Permalink
Improved test coverage for Selector exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhy committed Dec 14, 2024
1 parent 34fb153 commit e0019eb
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/test/java/org/jsoup/select/QueryParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;

import static org.jsoup.select.EvaluatorDebug.sexpr;
import static org.jsoup.select.Selector.SelectorParseException;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -103,21 +104,41 @@ public class QueryParserTest {
*/
}

@Test public void exceptionOnUncloseAttribute() {
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse("section > a[href=\"]"));

@Test
public void exceptionOnUncloseAttribute() {
Selector.SelectorParseException exception =
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse("section > a[href=\"]"));
assertEquals(
"Did not find balanced marker at 'href='",
exception.getMessage());
}

@Test public void testParsesSingleQuoteInContains() {
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse("p:contains(One \" One)"));
@Test
public void testParsesSingleQuoteInContains() {
Selector.SelectorParseException exception =
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse("p:contains(One \" One)"));
assertEquals("Did not find balanced marker at 'One '",
exception.getMessage());
}

@Test
public void exceptOnEmptySelector() {
SelectorParseException exception = assertThrows(SelectorParseException.class, () -> QueryParser.parse(""));
assertEquals("String must not be empty", exception.getMessage());
}

@Test public void exceptOnEmptySelector() {
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse(""));
@Test
public void exceptOnNullSelector() {
SelectorParseException exception = assertThrows(SelectorParseException.class, () -> QueryParser.parse(null));
assertEquals("String must not be empty", exception.getMessage());
}

@Test public void exceptOnNullSelector() {
assertThrows(Selector.SelectorParseException.class, () -> QueryParser.parse(null));
@Test
public void exceptOnUnhandledEvaluator() {
SelectorParseException exception =
assertThrows(SelectorParseException.class, () -> QueryParser.parse("div / foo"));
assertEquals("Could not parse query '/': unexpected token at '/'", exception.getMessage());
}

@Test public void okOnSpacesForeAndAft() {
Expand Down

0 comments on commit e0019eb

Please sign in to comment.