|
16 | 16 |
|
17 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; |
18 | 18 |
|
| 19 | +import org.htmlunit.cssparser.ErrorHandler; |
19 | 20 | import org.htmlunit.cssparser.parser.condition.Condition; |
20 | 21 | import org.htmlunit.cssparser.parser.condition.Condition.ConditionType; |
21 | 22 | import org.htmlunit.cssparser.parser.condition.HasPseudoClassCondition; |
@@ -235,17 +236,50 @@ public void syntaxErrors() throws Exception { |
235 | 236 | parseSelectors(":has(#, h2)", 1, 0, 0); |
236 | 237 | parseSelectors(":has([attr=], h2)", 1, 0, 0); |
237 | 238 | parseSelectors(":has([=value], h2)", 1, 0, 0); |
| 239 | + |
| 240 | + parseSelectors("::has(h2)", 1, 0, 0); |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * @throws Exception if any error occurs |
| 245 | + */ |
| 246 | + @Test |
| 247 | + public void syntaxErrorDoubleColon() throws Exception { |
| 248 | + String selector = "::has(h2)"; |
| 249 | + |
| 250 | + final CSSOMParser parser = new CSSOMParser(); |
| 251 | + ErrorHandler errorHandler = new ErrorHandler(); |
| 252 | + parser.setErrorHandler(errorHandler); |
| 253 | + |
| 254 | + parser.parseSelectors(selector); |
| 255 | + |
| 256 | + assertEquals(1, errorHandler.getErrorCount()); |
| 257 | + assertEquals(0, errorHandler.getFatalErrorCount()); |
| 258 | + assertEquals(0, errorHandler.getWarningCount()); |
| 259 | + |
| 260 | + assertEquals("\"::has(h2)\" is not a valid selector.", errorHandler.getErrorMessage()); |
| 261 | + |
| 262 | + selector = "p::has(h4)"; |
| 263 | + errorHandler = new ErrorHandler(); |
| 264 | + parser.setErrorHandler(errorHandler); |
| 265 | + parser.parseSelectors(selector); |
| 266 | + |
| 267 | + assertEquals(1, errorHandler.getErrorCount()); |
| 268 | + assertEquals(0, errorHandler.getFatalErrorCount()); |
| 269 | + assertEquals(0, errorHandler.getWarningCount()); |
| 270 | + |
| 271 | + assertEquals("\"::has(h4)\" is not a valid selector.", errorHandler.getErrorMessage()); |
238 | 272 | } |
239 | 273 |
|
240 | 274 | /** |
241 | 275 | * @throws Exception if any error occurs |
242 | 276 | */ |
243 | 277 | @Test |
244 | 278 | public void pseudoElementsInside() throws Exception { |
245 | | - // todo parseSelectors("div:has(p::before)", 1, 0, 0); |
246 | | - // todo parseSelectors("section:has(::first-line)", 1, 0, 0); |
247 | | - // todo parseSelectors("article:has(span::after)", 1, 0, 0); |
248 | | - // todo parseSelectors("div:has(p:has(::before))", 1, 0, 0); |
| 279 | + parseSelectors("div:has(p::before)", 0, 0, 0); |
| 280 | + parseSelectors("section:has(::first-line)", 0, 0, 0); |
| 281 | + parseSelectors("article:has(span::after)", 0, 0, 0); |
| 282 | + parseSelectors("div:has(p:has(::before))", 0, 0, 0); |
249 | 283 | } |
250 | 284 |
|
251 | 285 | /** |
|
0 commit comments