Fix mdbook-core book tests
These tests were moved in https://github.com/rust-lang/mdBook/pull/2766, but the `mod tests` was missing. This fixes this missing `mod`, and updates the tests so that they pass.
This commit is contained in:
parent
6be8e526d6
commit
24c7ffcd62
2 changed files with 100 additions and 98 deletions
|
|
@ -6,6 +6,9 @@ use std::fmt::{self, Display, Formatter};
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// A tree structure representing a book.
|
||||
///
|
||||
/// For the moment a book is just a collection of [`BookItems`] which are
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ fn section_number_has_correct_dotted_representation() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn book_iter_iterates_over_sequential_items() {
|
||||
let sections = vec![
|
||||
#[test]
|
||||
fn book_iter_iterates_over_sequential_items() {
|
||||
let items = vec![
|
||||
BookItem::Chapter(Chapter {
|
||||
name: String::from("Chapter 1"),
|
||||
content: String::from("# Chapter 1"),
|
||||
|
|
@ -24,18 +24,18 @@ fn section_number_has_correct_dotted_representation() {
|
|||
}),
|
||||
BookItem::Separator,
|
||||
];
|
||||
let book = Book::new_with_sections(sections);
|
||||
let book = Book::new_with_items(items);
|
||||
|
||||
let should_be: Vec<_> = book.sections.iter().collect();
|
||||
|
||||
let got: Vec<_> = book.iter().collect();
|
||||
|
||||
assert_eq!(got, should_be);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn for_each_mut_visits_all_items() {
|
||||
let sections = vec![
|
||||
#[test]
|
||||
fn for_each_mut_visits_all_items() {
|
||||
let items = vec![
|
||||
BookItem::Chapter(Chapter {
|
||||
name: String::from("Chapter 1"),
|
||||
content: String::from("# Chapter 1"),
|
||||
|
|
@ -61,7 +61,7 @@ fn section_number_has_correct_dotted_representation() {
|
|||
}),
|
||||
BookItem::Separator,
|
||||
];
|
||||
let mut book = Book::new_with_sections(sections);
|
||||
let mut book = Book::new_with_items(items);
|
||||
|
||||
let num_items = book.iter().count();
|
||||
let mut visited = 0;
|
||||
|
|
@ -69,11 +69,11 @@ fn section_number_has_correct_dotted_representation() {
|
|||
book.for_each_mut(|_| visited += 1);
|
||||
|
||||
assert_eq!(visited, num_items);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iterate_over_nested_book_items() {
|
||||
let sections = vec![
|
||||
#[test]
|
||||
fn iterate_over_nested_book_items() {
|
||||
let items = vec![
|
||||
BookItem::Chapter(Chapter {
|
||||
name: String::from("Chapter 1"),
|
||||
content: String::from("# Chapter 1"),
|
||||
|
|
@ -99,7 +99,7 @@ fn section_number_has_correct_dotted_representation() {
|
|||
}),
|
||||
BookItem::Separator,
|
||||
];
|
||||
let book = Book::new_with_sections(sections);
|
||||
let book = Book::new_with_items(items);
|
||||
|
||||
let got: Vec<_> = book.iter().collect();
|
||||
|
||||
|
|
@ -120,5 +120,4 @@ fn section_number_has_correct_dotted_representation() {
|
|||
];
|
||||
|
||||
assert_eq!(chapter_names, should_be);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue