use crate::helpers::AftProcess;
use std::fs;
use tempfile::TempDir;
const SAMPLE_QMD: &str = r#"---
title: My Quarto Document
author: Jane Doe
---
Setext Heading
==============
Some text under setext heading.
# Introduction
This is an introduction.
```{r}
# Some R code
x <- 1:10
plot(x)
```
## Section {#sec-id}
Some text under section with attribute.
"#;
#[test]
fn quarto_outline_extracts_headings() {
let dir = TempDir::new().unwrap();
let qmd_file = dir.path().join("document.qmd");
fs::write(&qmd_file, SAMPLE_QMD).unwrap();
let mut aft = AftProcess::spawn();
aft.configure(dir.path());
let resp = aft.send(&format!(
r#"{{"id":"qmd-1","command":"outline","file":{}}}"#,
crate::helpers::json_string(&qmd_file.display())
));
assert_eq!(resp["success"], true, "outline should succeed: {:?}", resp);
let text = resp["text"]
.as_str()
.expect("text field should be a string");
assert!(text.contains(" h "), "headings should use 'h' kind");
assert!(text.contains("Introduction"), "should have Introduction");
assert!(
text.contains("Setext Heading"),
"should have Setext Heading"
);
assert!(
text.contains("Section {#sec-id}"),
"should have Section {{#sec-id}}"
);
}