Started cleaning up some of the lints and warnings

This commit is contained in:
Michael Bryan 2017-07-08 17:55:00 +08:00
parent 4202ead962
commit 02d1d9317d
6 changed files with 15 additions and 16 deletions

View File

@ -43,7 +43,6 @@ ws = { version = "0.7", optional = true}
# Tests # Tests
[dev-dependencies] [dev-dependencies]
tempdir = "0.3.4" tempdir = "0.3.4"
pretty_assertions = "0.2.1"
[build-dependencies] [build-dependencies]
error-chain = "0.11" error-chain = "0.11"

View File

@ -87,9 +87,6 @@ extern crate serde;
extern crate serde_json; extern crate serde_json;
extern crate tempdir; extern crate tempdir;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[cfg(test)] #[cfg(test)]
extern crate tempdir; extern crate tempdir;

View File

@ -122,6 +122,13 @@ fn load_chapter<P: AsRef<Path>>(link: &Link, src_dir: P) -> Result<Chapter> {
} }
/// A depth-first iterator over the items in a book. /// A depth-first iterator over the items in a book.
///
/// # Note
///
/// This struct shouldn't be created directly, instead prefer the
/// [`Book::iter()`] method.
///
/// [`Book::iter()`]: struct.Book.html#method.iter
pub struct BookItems<'a> { pub struct BookItems<'a> {
items: VecDeque<&'a BookItem>, items: VecDeque<&'a BookItem>,
} }
@ -239,7 +246,7 @@ And here is some more text.
#[test] #[test]
fn load_a_book_with_a_single_chapter() { fn load_a_book_with_a_single_chapter() {
let (link, temp) = dummy_link(); let (link, _temp) = dummy_link();
let summary = Summary { let summary = Summary {
numbered_chapters: vec![SummaryItem::Link(link)], numbered_chapters: vec![SummaryItem::Link(link)],
..Default::default() ..Default::default()

View File

@ -18,7 +18,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use std::path::{Path, PathBuf}; use std::path::Path;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use errors::*; use errors::*;
@ -27,6 +27,7 @@ mod summary;
mod book; mod book;
pub use self::book::{Book, BookItems, BookItem, Chapter}; pub use self::book::{Book, BookItems, BookItem, Chapter};
pub use self::summary::SectionNumber;
use self::book::load_book_from_disk; use self::book::load_book_from_disk;
use self::summary::parse_summary; use self::summary::parse_summary;

View File

@ -2,7 +2,6 @@ use std::fmt::{self, Formatter, Display};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use pulldown_cmark::{self, Event, Tag}; use pulldown_cmark::{self, Event, Tag};
use errors::*; use errors::*;
@ -248,7 +247,7 @@ impl<'a> SummaryParser<'a> {
match self.state { match self.state {
State::Begin => self.step_start(next_event)?, State::Begin => self.step_start(next_event)?,
State::PrefixChapters => self.step_prefix(next_event)?, State::PrefixChapters => self.step_prefix(next_event)?,
State::NumberedChapters(n) => self.step_numbered(next_event, n)?, State::NumberedChapters(_) => self.step_numbered(next_event)?,
State::SuffixChapters => self.step_suffix(next_event)?, State::SuffixChapters => self.step_suffix(next_event)?,
State::End => {}, State::End => {},
} }
@ -316,7 +315,7 @@ impl<'a> SummaryParser<'a> {
/// section and need to parse the suffix section. /// section and need to parse the suffix section.
/// ///
/// Otherwise, ignore the event. /// Otherwise, ignore the event.
fn step_numbered(&mut self, event: Event, nesting: u32) -> Result<()> { fn step_numbered(&mut self, event: Event) -> Result<()> {
match event { match event {
Event::Start(Tag::Item) => { Event::Start(Tag::Item) => {
let it = self.parse_item().chain_err( let it = self.parse_item().chain_err(
@ -448,10 +447,6 @@ fn push_item_at_nesting_level(links: &mut Vec<SummaryItem>, mut item: SummaryIte
links.push(item); links.push(item);
Ok(section_number) Ok(section_number)
} else { } else {
let next_level = level - 1;
let index_for_item = links.len() + 1;
// FIXME: This bit needs simplifying!
let (index, last_link) = get_last_link(links).chain_err(|| { let (index, last_link) = get_last_link(links).chain_err(|| {
format!("The list of links needs to be {} levels deeper (current position {})", format!("The list of links needs to be {} levels deeper (current position {})",
level, section_number) level, section_number)
@ -465,6 +460,7 @@ fn push_item_at_nesting_level(links: &mut Vec<SummaryItem>, mut item: SummaryIte
/// Gets a pointer to the last `Link` in a list of `SummaryItem`s, and its /// Gets a pointer to the last `Link` in a list of `SummaryItem`s, and its
/// index. /// index.
fn get_last_link(links: &mut [SummaryItem]) -> Result<(usize, &mut Link)> { fn get_last_link(links: &mut [SummaryItem]) -> Result<(usize, &mut Link)> {
// TODO: This should probably be integrated into `Link::push_item()`
links links
.iter_mut() .iter_mut()
.enumerate() .enumerate()

View File

@ -1,10 +1,7 @@
//! Integration tests for loading a book into memory //! Integration tests for loading a book into memory
#[macro_use]
extern crate pretty_assertions;
extern crate mdbook; extern crate mdbook;
extern crate env_logger; extern crate env_logger;
extern crate tempdir;
use std::path::PathBuf; use std::path::PathBuf;
@ -13,6 +10,8 @@ use mdbook::loader::load_book;
#[test] #[test]
fn load_the_example_book() { fn load_the_example_book() {
env_logger::init().ok();
let example_src_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) let example_src_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("book-example") .join("book-example")
.join("src"); .join("src");