From 20d42a53d3fabeff1c3ca687bb1d41cfa0850d37 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 19:11:07 -0700 Subject: [PATCH] Migrate rendered_code_has_playground_stuff to BookTest --- tests/rendered_output.rs | 15 --------------- tests/testsuite/main.rs | 1 + tests/testsuite/playground.rs | 18 ++++++++++++++++++ .../playground_on_rust_code/book.toml | 2 ++ .../playground_on_rust_code/src/SUMMARY.md | 3 +++ .../playground_on_rust_code/src/index.md | 5 +++++ 6 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tests/testsuite/playground.rs create mode 100644 tests/testsuite/playground/playground_on_rust_code/book.toml create mode 100644 tests/testsuite/playground/playground_on_rust_code/src/SUMMARY.md create mode 100644 tests/testsuite/playground/playground_on_rust_code/src/index.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index a231bf16..8552d6f4 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -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(); diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index e2a3ebd9..5b2d7db1 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -9,6 +9,7 @@ mod includes; mod index; mod init; mod markdown; +mod playground; mod prelude { pub use crate::book_test::BookTest; diff --git a/tests/testsuite/playground.rs b/tests/testsuite/playground.rs new file mode 100644 index 00000000..5cbd7ab1 --- /dev/null +++ b/tests/testsuite/playground.rs @@ -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##" +

Rust Sample

+
#![allow(unused)]
+fn main() {
+let x = 1;
+}
+"##]], + ); +} diff --git a/tests/testsuite/playground/playground_on_rust_code/book.toml b/tests/testsuite/playground/playground_on_rust_code/book.toml new file mode 100644 index 00000000..7bf7c972 --- /dev/null +++ b/tests/testsuite/playground/playground_on_rust_code/book.toml @@ -0,0 +1,2 @@ +[book] +title = "playground_on_rust_code" diff --git a/tests/testsuite/playground/playground_on_rust_code/src/SUMMARY.md b/tests/testsuite/playground/playground_on_rust_code/src/SUMMARY.md new file mode 100644 index 00000000..6f47d01a --- /dev/null +++ b/tests/testsuite/playground/playground_on_rust_code/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Rust Playground](./index.md) diff --git a/tests/testsuite/playground/playground_on_rust_code/src/index.md b/tests/testsuite/playground/playground_on_rust_code/src/index.md new file mode 100644 index 00000000..93234d98 --- /dev/null +++ b/tests/testsuite/playground/playground_on_rust_code/src/index.md @@ -0,0 +1,5 @@ +# Rust Sample + +```rust +let x = 1; +```