use std::fs;
use std::process::Command;
fn setup_test_files() -> tempfile::TempDir {
let temp_dir = tempfile::tempdir().unwrap();
let base_path = temp_dir.path();
fs::write(base_path.join("emphasis_heading.md"), "**This should be a heading**")
.expect("Failed to write test file");
temp_dir
}
#[test]
fn test_heading_emphasis_detection() {
let temp_dir = setup_test_files();
let base_path = temp_dir.path();
let output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
.current_dir(base_path)
.args(["check", "--enable=MD036", "emphasis_heading.md"])
.output()
.unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
let combined_output = format!("{stderr}{stdout}");
assert!(
combined_output.contains("MD036"),
"MD036 should detect emphasis used as heading. Output: {combined_output}"
);
let _output = Command::new(env!("CARGO_BIN_EXE_rumdl"))
.current_dir(base_path)
.args(["--fix", "--enable=MD036", "emphasis_heading.md"])
.output()
.unwrap();
let fixed_content = fs::read_to_string(base_path.join("emphasis_heading.md")).expect("Could not read fixed file");
assert!(
fixed_content.contains("**This should be a heading**"),
"Emphasis should remain unchanged (no automatic fix)"
);
assert!(
!fixed_content.contains("## This should be a heading"),
"Emphasis should NOT be converted to a heading automatically"
);
}