File size: 3,389 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""Test is selectors."""
from .. import util
from soupsieve import SelectorSyntaxError


class TestIs(util.TestCase):
    """Test is selectors."""

    MARKUP = """
    <div>
    <p>Some text <span id="1"> in a paragraph</span>.
    <a id="2" href="http://google.com">Link</a>
    </p>
    </div>
    """

    def test_is(self):
        """Test multiple selectors with "is"."""

        self.assert_selector(
            self.MARKUP,
            ":is(span, a)",
            ["1", "2"],
            flags=util.HTML
        )

    def test_is_multi_comma(self):
        """Test multiple selectors but with an empty slot due to multiple commas."""

        self.assert_selector(
            self.MARKUP,
            ":is(span, , a)",
            ["1", "2"],
            flags=util.HTML
        )

    def test_is_leading_comma(self):
        """Test multiple selectors but with an empty slot due to leading commas."""

        self.assert_selector(
            self.MARKUP,
            ":is(, span, a)",
            ["1", "2"],
            flags=util.HTML
        )

    def test_is_trailing_comma(self):
        """Test multiple selectors but with an empty slot due to trailing commas."""

        self.assert_selector(
            self.MARKUP,
            ":is(span, a, )",
            ["1", "2"],
            flags=util.HTML
        )

    def test_is_empty(self):
        """Test empty `:is()` selector list."""

        self.assert_selector(
            self.MARKUP,
            ":is()",
            [],
            flags=util.HTML
        )

    def test_nested_is(self):
        """Test multiple nested selectors."""

        self.assert_selector(
            self.MARKUP,
            ":is(span, a:is(#\\32))",
            ["1", "2"],
            flags=util.HTML
        )

        self.assert_selector(
            self.MARKUP,
            ":is(span, a:is(#\\32))",
            ["1", "2"],
            flags=util.HTML
        )

    def test_is_with_other_pseudo(self):
        """Test `:is()` behavior when paired with `:not()`."""

        # Each pseudo class is evaluated separately
        # So this will not match
        self.assert_selector(
            self.MARKUP,
            ":is(span):not(span)",
            [],
            flags=util.HTML
        )

    def test_multiple_is(self):
        """Test `:is()` behavior when paired with `:not()`."""

        # Each pseudo class is evaluated separately
        # So this will not match
        self.assert_selector(
            self.MARKUP,
            ":is(span):is(div)",
            [],
            flags=util.HTML
        )

        # Each pseudo class is evaluated separately
        # So this will match
        self.assert_selector(
            self.MARKUP,
            ":is(a):is(#\\32)",
            ['2'],
            flags=util.HTML
        )

    def test_invalid_pseudo_class_start_combinator(self):
        """Test invalid start combinator in pseudo-classes other than `:has()`."""

        self.assert_raises(':is(> div)', SelectorSyntaxError)
        self.assert_raises(':is(div, > div)', SelectorSyntaxError)

    def test_invalid_pseudo_orphan_close(self):
        """Test invalid, orphaned pseudo close."""

        self.assert_raises('div)', SelectorSyntaxError)

    def test_invalid_pseudo_open(self):
        """Test invalid pseudo close."""

        self.assert_raises(':is(div', SelectorSyntaxError)