|
| 1 | +/* |
| 2 | + * Copyright (c) 2019-2024 Ronald Brill. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | +package org.htmlunit.cssparser.parser; |
| 16 | + |
| 17 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 18 | + |
| 19 | +import org.htmlunit.cssparser.parser.condition.Condition; |
| 20 | +import org.htmlunit.cssparser.parser.condition.Condition.ConditionType; |
| 21 | +import org.htmlunit.cssparser.parser.condition.IsPseudoClassCondition; |
| 22 | +import org.htmlunit.cssparser.parser.selector.ElementSelector; |
| 23 | +import org.htmlunit.cssparser.parser.selector.Selector; |
| 24 | +import org.htmlunit.cssparser.parser.selector.Selector.SelectorType; |
| 25 | +import org.htmlunit.cssparser.parser.selector.SelectorList; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +/** |
| 29 | + * @author Ronald Brill |
| 30 | + */ |
| 31 | +public class CSS3ParserIsSelectorTest extends AbstractCSSParserTest { |
| 32 | + |
| 33 | + /** |
| 34 | + * @throws Exception if any error occurs |
| 35 | + */ |
| 36 | + @Test |
| 37 | + public void isElementType() throws Exception { |
| 38 | + // element name |
| 39 | + final SelectorList selectors = createSelectors(":is(ol, ul)"); |
| 40 | + assertEquals("*:is(ol, ul)", selectors.get(0).toString()); |
| 41 | + |
| 42 | + assertEquals(1, selectors.size()); |
| 43 | + final Selector selector = selectors.get(0); |
| 44 | + |
| 45 | + assertEquals(SelectorType.ELEMENT_NODE_SELECTOR, selector.getSelectorType()); |
| 46 | + |
| 47 | + final ElementSelector elemSel = (ElementSelector) selector; |
| 48 | + assertEquals(1, elemSel.getConditions().size()); |
| 49 | + |
| 50 | + final Condition condition = elemSel.getConditions().get(0); |
| 51 | + assertEquals(ConditionType.IS_PSEUDO_CLASS_CONDITION, condition.getConditionType()); |
| 52 | + |
| 53 | + final IsPseudoClassCondition pseudo = (IsPseudoClassCondition) condition; |
| 54 | + assertEquals("ol, ul", pseudo.getValue()); |
| 55 | + assertEquals(":is(ol, ul)", pseudo.toString()); |
| 56 | + |
| 57 | + final SelectorList conditionSelectors = pseudo.getSelectors(); |
| 58 | + assertEquals(2, conditionSelectors.size()); |
| 59 | + final Selector conditionSelector = conditionSelectors.get(0); |
| 60 | + final ElementSelector conditionElemSelector = (ElementSelector) conditionSelector; |
| 61 | + assertEquals("ol", conditionElemSelector.getElementName()); |
| 62 | + } |
| 63 | +} |
0 commit comments