Skip to content

Commit d11e3f6

Browse files
Refactoring to make the test more readable
1 parent 95609cf commit d11e3f6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tests/regression.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! These tests will need to be updated every time the example book changes.
77
//! Hopefully Travis will let you know when that happens.
88
9-
#![feature(conservative_impl_trait)]
109

1110
extern crate mdbook;
1211
#[macro_use]
@@ -18,7 +17,7 @@ extern crate walkdir;
1817
mod helpers;
1918

2019
use std::path::Path;
21-
use walkdir::{WalkDir, WalkDirIterator};
20+
use walkdir::{DirEntry, WalkDir, WalkDirIterator};
2221
use select::document::Document;
2322
use select::predicate::{Class, Descendant, Name, Predicate};
2423

@@ -66,7 +65,7 @@ fn chapter_files_were_rendered_to_html() {
6665

6766
let chapter_files = WalkDir::new(&src)
6867
.into_iter()
69-
.filter_entry(|entry| entry.file_name().to_string_lossy().ends_with(".md"))
68+
.filter_entry(|entry| entry_ends_with(entry, ".md"))
7069
.filter_map(|entry| entry.ok())
7170
.map(|entry| entry.path().to_path_buf())
7271
.filter(|path| path.file_name().unwrap() != "SUMMARY");
@@ -79,6 +78,12 @@ fn chapter_files_were_rendered_to_html() {
7978
}
8079
}
8180

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
8287
fn root_index_html() -> Document {
8388
let temp = helpers::build_example_book();
8489

@@ -92,13 +97,10 @@ fn check_third_toc_level() {
9297
let doc = root_index_html();
9398
let should_be = TOC_THIRD_LEVEL;
9499

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())
102104
.collect();
103105
assert_eq!(children_of_children_of_children, should_be);
104106
}

0 commit comments

Comments
 (0)