From aa29ef04a2a79d278c6f3c21e8f53ee438e8d014 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 19:11:53 -0700 Subject: [PATCH] Migrate rendered_code_does_not_have_playground_stuff_in_html_when_disabled_in_config to BookTest --- tests/rendered_output.rs | 19 ------------------- tests/testsuite/playground.rs | 12 ++++++++++++ .../playground/disabled_playground/book.toml | 5 +++++ .../disabled_playground/src/SUMMARY.md | 3 +++ .../disabled_playground/src/index.md | 5 +++++ 5 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 tests/testsuite/playground/disabled_playground/book.toml create mode 100644 tests/testsuite/playground/disabled_playground/src/SUMMARY.md create mode 100644 tests/testsuite/playground/disabled_playground/src/index.md diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 8552d6f4..88d44fef 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -93,25 +93,6 @@ fn check_correct_relative_links_in_print_page() { ); } -#[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 chapter_content_appears_in_rendered_document() { let content = vec![ diff --git a/tests/testsuite/playground.rs b/tests/testsuite/playground.rs index 5cbd7ab1..1983757d 100644 --- a/tests/testsuite/playground.rs +++ b/tests/testsuite/playground.rs @@ -16,3 +16,15 @@ fn playground_on_rust_code() { "##]], ); } + +// When the playground is disabled, there should be no playground class. +#[test] +fn disabled_playground() { + BookTest::from_dir("playground/disabled_playground").check_main_file( + "book/index.html", + str![[r##" +

Rust Sample

+
let x = 1;
+"##]], + ); +} diff --git a/tests/testsuite/playground/disabled_playground/book.toml b/tests/testsuite/playground/disabled_playground/book.toml new file mode 100644 index 00000000..3a9b2297 --- /dev/null +++ b/tests/testsuite/playground/disabled_playground/book.toml @@ -0,0 +1,5 @@ +[book] +title = "playground_on_rust_code" + +[output.html.playground] +runnable = false diff --git a/tests/testsuite/playground/disabled_playground/src/SUMMARY.md b/tests/testsuite/playground/disabled_playground/src/SUMMARY.md new file mode 100644 index 00000000..6f47d01a --- /dev/null +++ b/tests/testsuite/playground/disabled_playground/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [Rust Playground](./index.md) diff --git a/tests/testsuite/playground/disabled_playground/src/index.md b/tests/testsuite/playground/disabled_playground/src/index.md new file mode 100644 index 00000000..93234d98 --- /dev/null +++ b/tests/testsuite/playground/disabled_playground/src/index.md @@ -0,0 +1,5 @@ +# Rust Sample + +```rust +let x = 1; +```