From 54e55efa70e9d1dc9016b7f0d720fd9ea7d38486 Mon Sep 17 00:00:00 2001 From: Sytse Reitsma Date: Sat, 13 Apr 2019 14:08:44 +0200 Subject: [PATCH] Wrote unit test for reserved print.md file name --- src/renderer/html_handlebars/hbs_renderer.rs | 39 +++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index b5ef228d..13f5b4ec 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -1,4 +1,4 @@ -use book::{Book, BookItem}; +use book::{Book, BookItem, Chapter}; use config::{Config, HtmlConfig, Playpen}; use errors::*; use renderer::html_handlebars::helpers; @@ -669,4 +669,41 @@ mod tests { assert_eq!(got, should_be); } } + + #[test] + fn print_dot_md_is_reserved() { + let handlebars = HtmlHandlebars::new(); + let item = BookItem::Chapter(Chapter::new( + "Goodbye World", + String::new(), + "print.md", + Vec::new(), + )); + let ctx = RenderItemContext { + handlebars: &Handlebars::new(), + destination: PathBuf::new(), + data: serde_json::from_str("{}").unwrap(), + is_index: false, + html_config: HtmlConfig { + curly_quotes: true, + google_analytics: Some(String::from("123456")), + additional_css: vec![PathBuf::from("./foo/bar/baz.css")], + theme: Some(PathBuf::from("./themedir")), + default_theme: Some(String::from("rust")), + playpen: Playpen { + editable: true, + copy_js: true, + }, + git_repository_url: Some(String::from("https://foo.com/")), + git_repository_icon: Some(String::from("fa-code-fork")), + ..Default::default() + } + }; + + let mut content = String::new(); + match handlebars.render_item(&item, ctx, &mut content) { + Ok(_) => assert!(false, "Expected a failure"), + Err(error)=> assert_eq!(error.to_string(), "print.md is reserved for internal use"), + }; + } }