From f8926a75160bec4a162958480be250ea639ef116 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 18 Feb 2016 23:47:17 +0100 Subject: [PATCH] Add incomplete test for fill_config --- src/config/mod.rs | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/config/mod.rs b/src/config/mod.rs index 2546afc0..b4eb27e4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,3 +1,53 @@ +//! # Configuration file +//! +//! This module handles the loading of the configuration from the `book.toml` configuration file. +//! The configuration file looks like this: +//! +//! ```toml +//! title = "mdBook" +//! description = """ +//! This is a command line utility to generate books from markdown files +//! """ +//! +//! [[author]] +//! name = "Mathieu David" +//! email = "mathieudavid@mathieudavid.org" +//! # other fields could be added in the future +//! +//! [source] +//! path = "src/" +//! +//! # "outputs" is a table where each entry is the identifier of a renderer +//! # containing the configuration options for that renderer +//! [outputs] +//! html = { path = "book/" } +//! # OR alternatively +//! # [outputs.html] +//! # path = "book/" +//! +//! [languages] +//! en = { name = "English", default = true } +//! fr = { name = "Français" } +//! # OR alternatively +//! # [languages.en] +//! # name = "English" +//! # default = true +//! # +//! # [languages.fr] +//! # name = "Français" +//! +//! [plugins] +//! syntax-highlighting = { enabled = true, default_language = "rust" } +//! code-line-hiding = { enabled = true, hide_pattern = "#" } +//! rust-playpen = { enabled = true } +//! # OR alternatively +//! # [plugins.syntax-highlighting] +//! # enabled = true +//! # default_language = "rust" +//! # +//! # [plugins.code-line-hiding] +//! # ... + extern crate toml; use std::path::{Path, PathBuf}; @@ -219,3 +269,69 @@ impl Plugin { self.config.as_ref().map(|x| &*x) } } + + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn fill_config() { + let mut config = Config::new(); + + let toml = r##"title = "mdBook" +description = """ +This is a command line utility to generate books from markdown files +""" + +[[author]] +name = "Mathieu David" +email = "mathieudavid@mathieudavid.org" +# other fields could be added + +[source] +path = "src/" + +# "outputs" is a table where each entry is the identifier of a renderer +# containing the configuration options for that renderer +[outputs] +html = { path = "book/" } +pdf = { path = "pdf/mdBook.pdf" } +# OR alternatively +# [outputs.html] +# path = "book/" +# +# [outputs.pdf] +# path = "pdf/mdBook.pdf" + +[languages] +en = { name = "English", default = true } +fr = { name = "Français" } +# OR alternatively +# [languages.en] +# name = "English" +# default = true +# +# [languages.fr] +# name = "Français" + +[plugins] +syntax-highlighting = { enabled = true, default_language = "rust" } +code-line-hiding = { enabled = true, hide_pattern = "#" } +rust-playpen = { enabled = true } +# OR alternatively +# [plugins.syntax-highlighting] +# enabled = true +# default_language = "rust" +# +# [plugins.code-line-hiding] +# ... +"##; + + config.fill_config(toml); + + assert_eq!(config.title(), "mdBook"); + assert_eq!(config.description(), "mdBook is a utility to create books from markdown files"); + } +}