Merge pull request #2811 from ehuss/core-book-tests
Fix mdbook-core book tests
This commit is contained in:
commit
45e700db00
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::ops::{Deref, DerefMut};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
/// A tree structure representing a book.
|
/// A tree structure representing a book.
|
||||||
///
|
///
|
||||||
/// For the moment a book is just a collection of [`BookItems`] which are
|
/// 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]
|
#[test]
|
||||||
fn book_iter_iterates_over_sequential_items() {
|
fn book_iter_iterates_over_sequential_items() {
|
||||||
let sections = vec![
|
let items = vec![
|
||||||
BookItem::Chapter(Chapter {
|
BookItem::Chapter(Chapter {
|
||||||
name: String::from("Chapter 1"),
|
name: String::from("Chapter 1"),
|
||||||
content: String::from("# Chapter 1"),
|
content: String::from("# Chapter 1"),
|
||||||
|
|
@ -24,18 +24,18 @@ fn section_number_has_correct_dotted_representation() {
|
||||||
}),
|
}),
|
||||||
BookItem::Separator,
|
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 should_be: Vec<_> = book.sections.iter().collect();
|
||||||
|
|
||||||
let got: Vec<_> = book.iter().collect();
|
let got: Vec<_> = book.iter().collect();
|
||||||
|
|
||||||
assert_eq!(got, should_be);
|
assert_eq!(got, should_be);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn for_each_mut_visits_all_items() {
|
fn for_each_mut_visits_all_items() {
|
||||||
let sections = vec![
|
let items = vec![
|
||||||
BookItem::Chapter(Chapter {
|
BookItem::Chapter(Chapter {
|
||||||
name: String::from("Chapter 1"),
|
name: String::from("Chapter 1"),
|
||||||
content: String::from("# Chapter 1"),
|
content: String::from("# Chapter 1"),
|
||||||
|
|
@ -61,7 +61,7 @@ fn section_number_has_correct_dotted_representation() {
|
||||||
}),
|
}),
|
||||||
BookItem::Separator,
|
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 num_items = book.iter().count();
|
||||||
let mut visited = 0;
|
let mut visited = 0;
|
||||||
|
|
@ -69,11 +69,11 @@ fn section_number_has_correct_dotted_representation() {
|
||||||
book.for_each_mut(|_| visited += 1);
|
book.for_each_mut(|_| visited += 1);
|
||||||
|
|
||||||
assert_eq!(visited, num_items);
|
assert_eq!(visited, num_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn iterate_over_nested_book_items() {
|
fn iterate_over_nested_book_items() {
|
||||||
let sections = vec![
|
let items = vec![
|
||||||
BookItem::Chapter(Chapter {
|
BookItem::Chapter(Chapter {
|
||||||
name: String::from("Chapter 1"),
|
name: String::from("Chapter 1"),
|
||||||
content: String::from("# Chapter 1"),
|
content: String::from("# Chapter 1"),
|
||||||
|
|
@ -99,7 +99,7 @@ fn section_number_has_correct_dotted_representation() {
|
||||||
}),
|
}),
|
||||||
BookItem::Separator,
|
BookItem::Separator,
|
||||||
];
|
];
|
||||||
let book = Book::new_with_sections(sections);
|
let book = Book::new_with_items(items);
|
||||||
|
|
||||||
let got: Vec<_> = book.iter().collect();
|
let got: Vec<_> = book.iter().collect();
|
||||||
|
|
||||||
|
|
@ -120,5 +120,4 @@ fn section_number_has_correct_dotted_representation() {
|
||||||
];
|
];
|
||||||
|
|
||||||
assert_eq!(chapter_names, should_be);
|
assert_eq!(chapter_names, should_be);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue