extern crate tera; extern crate front_matter; extern crate templates; extern crate rendering; extern crate config; use std::collections::HashMap; use std::path::Path; use tera::Tera; use config::Config; use front_matter::InsertAnchor; use templates::GUTENBERG_TERA; use rendering::{RenderContext, render_content}; #[test] fn can_do_render_content_simple() { let tera_ctx = Tera::default(); let permalinks_ctx = HashMap::new(); let config = Config::default(); let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content("hello", &context).unwrap(); assert_eq!(res.body, "

hello

\n"); } #[test] fn doesnt_highlight_code_block_with_highlighting_off() { let tera_ctx = Tera::default(); let permalinks_ctx = HashMap::new(); let mut config = Config::default(); config.highlight_code = false; let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content("```\n$ gutenberg server\n```", &context).unwrap(); assert_eq!( res.body, "
$ gutenberg server\n
\n" ); } #[test] fn can_highlight_code_block_no_lang() { let tera_ctx = Tera::default(); let permalinks_ctx = HashMap::new(); let mut config = Config::default(); config.highlight_code = true; let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content("```\n$ gutenberg server\n$ ping\n```", &context).unwrap(); assert_eq!( res.body, "
\n$ gutenberg server\n$ ping\n
" ); } #[test] fn can_highlight_code_block_with_lang() { let tera_ctx = Tera::default(); let permalinks_ctx = HashMap::new(); let mut config = Config::default(); config.highlight_code = true; let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content("```python\nlist.append(1)\n```", &context).unwrap(); assert_eq!( res.body, "
\nlist.append(1)\n
" ); } #[test] fn can_higlight_code_block_with_unknown_lang() { let tera_ctx = Tera::default(); let permalinks_ctx = HashMap::new(); let mut config = Config::default(); config.highlight_code = true; let context = RenderContext::new(&tera_ctx, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content("```yolo\nlist.append(1)\n```", &context).unwrap(); // defaults to plain text assert_eq!( res.body, "
\nlist.append(1)\n
" ); } #[test] fn can_render_shortcode() { let permalinks_ctx = HashMap::new(); let config = Config::default(); let context = RenderContext::new(&GUTENBERG_TERA, &config, "", &permalinks_ctx, Path::new("something"), InsertAnchor::None); let res = render_content(r#" Hello {{ youtube(id="ub36ffWAqgQ") }} "#, &context).unwrap(); assert!(res.body.contains("

Hello

\n
")); assert!(res.body.contains(r#"