use std::collections::HashMap; use tera::Tera; use config::Config; use front_matter::InsertAnchor; use rendering::{render_content, RenderContext}; use templates::ZOLA_TERA; use utils::slugs::SlugifyStrategy; #[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, &config.default_language, "", &permalinks_ctx, 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.markdown.highlight_code = false; let context = RenderContext::new( &tera_ctx, &config, &config.default_language, "", &permalinks_ctx, 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.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
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.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
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.markdown.highlight_code = true;
let context = RenderContext::new(
&tera_ctx,
&config,
&config.default_language,
"",
&permalinks_ctx,
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(
&ZOLA_TERA,
&config,
&config.default_language,
"",
&permalinks_ctx,
InsertAnchor::None,
);
let res = render_content(
r#"
Hello
{{ youtube(id="ub36ffWAqgQ") }}
"#,
&context,
)
.unwrap();
assert!(res.body.contains("Hello
\n