File tree 2 files changed +50
-0
lines changed 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,14 @@ pub struct Parser;
86
86
impl < ' i > parser:: Parser < ' i > for Parser {
87
87
type Impl = Simple ;
88
88
type Error = SelectorParseErrorKind < ' i > ;
89
+
90
+ fn parse_is_and_where ( & self ) -> bool {
91
+ true
92
+ }
93
+
94
+ fn parse_has ( & self ) -> bool {
95
+ true
96
+ }
89
97
}
90
98
91
99
/// A simple implementation of `SelectorImpl` with no pseudo-classes or pseudo-elements.
@@ -222,4 +230,22 @@ mod tests {
222
230
let s = "<failing selector>" ;
223
231
let _sel: Selector = s. try_into ( ) . unwrap ( ) ;
224
232
}
233
+
234
+ #[ test]
235
+ fn has_selector ( ) {
236
+ let s = ":has(a)" ;
237
+ let _sel: Selector = s. try_into ( ) . unwrap ( ) ;
238
+ }
239
+
240
+ #[ test]
241
+ fn is_selector ( ) {
242
+ let s = ":is(a)" ;
243
+ let _sel: Selector = s. try_into ( ) . unwrap ( ) ;
244
+ }
245
+
246
+ #[ test]
247
+ fn where_selector ( ) {
248
+ let s = ":where(a)" ;
249
+ let _sel: Selector = s. try_into ( ) . unwrap ( ) ;
250
+ }
225
251
}
Original file line number Diff line number Diff line change @@ -20,3 +20,27 @@ fn tag_with_newline() {
20
20
Some ( "https://github.com/causal-agent/scraper" )
21
21
) ;
22
22
}
23
+
24
+ #[ test]
25
+ fn has_selector ( ) {
26
+ let document = Html :: parse_fragment (
27
+ r#"
28
+ <div>
29
+ <div id="foo">
30
+ Hi There!
31
+ </div>
32
+ </div>
33
+ <ul>
34
+ <li>first</li>
35
+ <li>second</li>
36
+ <li>third</li>
37
+ </ul>
38
+ "# ,
39
+ ) ;
40
+
41
+ let selector = Selector :: parse ( "div:has(div#foo) + ul > li:nth-child(2)" ) . unwrap ( ) ;
42
+
43
+ let mut iter = document. select ( & selector) ;
44
+ let li = iter. next ( ) . unwrap ( ) ;
45
+ assert_eq ! ( li. inner_html( ) , "second" ) ;
46
+ }
You can’t perform that action at this time.
0 commit comments