add tests

This commit is contained in:
Shogo Takata 2022-03-26 15:34:07 +09:00
parent b85c3035fe
commit 0dca4d9b9f
No known key found for this signature in database
GPG Key ID: 93C92BE128D78ED2
2 changed files with 36 additions and 0 deletions

View File

@ -815,6 +815,22 @@ mod tests {
assert_eq!(got.html_config().unwrap(), html_should_be);
}
#[test]
fn disable_runnable() {
let src = r#"
[book]
title = "Some Book"
description = "book book book"
authors = ["Shogo Takata"]
[output.html.playground]
runnable = false
"#;
let got = Config::from_str(src).unwrap();
assert_eq!(got.html_config().unwrap().playground.runnable, false);
}
#[test]
fn edition_2015() {
let src = r#"

View File

@ -17,6 +17,7 @@ use std::ffi::OsStr;
use std::fs;
use std::io::Write;
use std::path::{Component, Path, PathBuf};
use std::str::FromStr;
use tempfile::Builder as TempFileBuilder;
use walkdir::{DirEntry, WalkDir};
@ -150,6 +151,25 @@ fn rendered_code_has_playground_stuff() {
assert_contains_strings(book_js, &[".playground"]);
}
#[test]
fn rendered_code_does_not_have_playground_stuff_in_html_when_disabled_in_config() {
let temp = DummyBook::new().build().unwrap();
let config = Config::from_str(
"
[output.html.playground]
runnable = false
",
)
.unwrap();
let md = MDBook::load_with_config(temp.path(), config).unwrap();
md.build().unwrap();
let nested = temp.path().join("book/first/nested.html");
let playground_class = vec![r#"class="playground""#];
assert_doesnt_contain_strings(nested, &playground_class);
}
#[test]
fn anchors_include_text_between_but_not_anchor_comments() {
let temp = DummyBook::new().build().unwrap();