in starlark/src/values/docs.rs [1008:1066]
fn parses_and_removes_sections_from_rust_docstring() {
let raw_docs = r#"This is an example docstring
We have some details up here that should not be parsed
# Some Section
```
# This is a commented out line in a codeblock
fn some_func() {}
```
# Example
First line of the section
Note that, unlike starlark doc strings,
we don't require indentation. The end of a
section is either a new section appearing,
or the end of the string.
# Last
This is something in the last section
"#;
let expected_docstring = DocString::from_docstring(
DocStringKind::Rust,
r#"This is an example docstring
We have some details up here that should not be parsed
# Some Section
```
fn some_func() {}
```
# Last
This is something in the last section
"#,
)
.unwrap();
let expected_sections = HashMap::from([(
"example".to_owned(),
concat!(
"First line of the section\n\n",
"Note that, unlike starlark doc strings,\n",
"we don't require indentation. The end of a\n",
"section is either a new section appearing,\n",
"or the end of the string.",
)
.to_owned(),
)]);
let ds = DocString::from_docstring(DocStringKind::Rust, raw_docs).unwrap();
let (new_ds, sections) = ds.parse_and_remove_sections(DocStringKind::Rust, &["example"]);
assert_eq!(new_ds, expected_docstring);
assert_eq!(sections, expected_sections);
}