Migrate rendered_code_has_playground_stuff to BookTest

This commit is contained in:
Eric Huss 2025-04-21 19:11:07 -07:00
parent 8c8f0a4dbf
commit 20d42a53d3
6 changed files with 29 additions and 15 deletions

View file

@ -93,21 +93,6 @@ fn check_correct_relative_links_in_print_page() {
);
}
#[test]
fn rendered_code_has_playground_stuff() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();
let nested = temp.path().join("book/first/nested.html");
let playground_class = vec![r#"class="playground""#];
assert_contains_strings(nested, &playground_class);
let book_js = temp.path().join("book/book.js");
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();

View file

@ -9,6 +9,7 @@ mod includes;
mod index;
mod init;
mod markdown;
mod playground;
mod prelude {
pub use crate::book_test::BookTest;

View file

@ -0,0 +1,18 @@
//! Tests for Rust playground support.
use crate::prelude::*;
// Verifies that a rust codeblock gets the playground class.
#[test]
fn playground_on_rust_code() {
BookTest::from_dir("playground/playground_on_rust_code").check_main_file(
"book/index.html",
str![[r##"
<h1 id="rust-sample"><a class="header" href="#rust-sample">Rust Sample</a></h1>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let x = 1;
<span class="boring">}</span></code></pre></pre>
"##]],
);
}

View file

@ -0,0 +1,2 @@
[book]
title = "playground_on_rust_code"

View file

@ -0,0 +1,3 @@
# Summary
- [Rust Playground](./index.md)

View file

@ -0,0 +1,5 @@
# Rust Sample
```rust
let x = 1;
```