in starlark/src/values/docs.rs [1153:1220]
fn parses_rust_function_docstring() {
let docstring = r#"This is an example docstring
Details here
# Arguments
* `arg_foo`: The argument named foo
`arg_bar`: The argument named bar. It has
a longer doc string that spans
over three lines
# Returns
A value
"#;
let kind = DocStringKind::Rust;
let return_type = Some(Type {
raw_type: "int".to_owned(),
});
let expected = Function {
docs: DocString::from_docstring(kind, "This is an example docstring\n\nDetails here"),
params: vec![
Param::Arg {
name: "arg_bar".to_owned(),
docs: DocString::from_docstring(
kind,
concat!(
"The argument named bar. It has\n",
"a longer doc string that spans\n",
"over three lines"
),
),
typ: None,
default_value: None,
},
Param::Arg {
name: "arg_foo".to_owned(),
docs: DocString::from_docstring(kind, "The argument named foo"),
typ: None,
default_value: None,
},
],
ret: Return {
docs: DocString::from_docstring(kind, "A value"),
typ: return_type.clone(),
},
};
let function_docs = Function::from_docstring(
kind,
|param_docs| {
param_docs
.into_iter()
.sorted_by(|l, r| Ord::cmp(&l.0, &r.0))
.map(|(name, docs)| Param::Arg {
name,
docs,
typ: None,
default_value: None,
})
.collect()
},
return_type,
Some(docstring),
);
assert_eq!(expected, function_docs);
}