6
6
//! These tests will need to be updated every time the example book changes.
7
7
//! Hopefully Travis will let you know when that happens.
8
8
9
- #![ feature( conservative_impl_trait) ]
10
9
11
10
extern crate mdbook;
12
11
#[ macro_use]
@@ -18,7 +17,7 @@ extern crate walkdir;
18
17
mod helpers;
19
18
20
19
use std:: path:: Path ;
21
- use walkdir:: { WalkDir , WalkDirIterator } ;
20
+ use walkdir:: { DirEntry , WalkDir , WalkDirIterator } ;
22
21
use select:: document:: Document ;
23
22
use select:: predicate:: { Class , Descendant , Name , Predicate } ;
24
23
@@ -66,7 +65,7 @@ fn chapter_files_were_rendered_to_html() {
66
65
67
66
let chapter_files = WalkDir :: new ( & src)
68
67
. into_iter ( )
69
- . filter_entry ( |entry| entry . file_name ( ) . to_string_lossy ( ) . ends_with ( ".md" ) )
68
+ . filter_entry ( |entry| entry_ends_with ( entry , ".md" ) )
70
69
. filter_map ( |entry| entry. ok ( ) )
71
70
. map ( |entry| entry. path ( ) . to_path_buf ( ) )
72
71
. filter ( |path| path. file_name ( ) . unwrap ( ) != "SUMMARY" ) ;
@@ -79,6 +78,12 @@ fn chapter_files_were_rendered_to_html() {
79
78
}
80
79
}
81
80
81
+ fn entry_ends_with ( entry : & DirEntry , ending : & str ) -> bool {
82
+ entry. file_name ( ) . to_string_lossy ( ) . ends_with ( ending)
83
+ }
84
+
85
+ /// Read the main page (`book/index.html`) and expose it as a DOM which we
86
+ /// can search with the `select` crate
82
87
fn root_index_html ( ) -> Document {
83
88
let temp = helpers:: build_example_book ( ) ;
84
89
@@ -92,13 +97,10 @@ fn check_third_toc_level() {
92
97
let doc = root_index_html ( ) ;
93
98
let should_be = TOC_THIRD_LEVEL ;
94
99
95
- let children_of_children_of_children: Vec < String > = doc. find (
96
- Class ( "chapter" )
97
- . descendant ( Name ( "li" ) )
98
- . descendant ( Name ( "li" ) )
99
- . descendant ( Name ( "li" ) )
100
- . descendant ( Name ( "a" ) ) ,
101
- ) . map ( |elem| elem. text ( ) . trim ( ) . to_string ( ) )
100
+ let pred = descendants ! ( Class ( "chapter" ) , Name ( "li" ) , Name ( "li" ) , Name ( "li" ) , Name ( "a" ) ) ;
101
+
102
+ let children_of_children_of_children: Vec < String > = doc. find ( pred)
103
+ . map ( |elem| elem. text ( ) . trim ( ) . to_string ( ) )
102
104
. collect ( ) ;
103
105
assert_eq ! ( children_of_children_of_children, should_be) ;
104
106
}
0 commit comments