fn parses_starlark_function_docstring()

in starlark/src/values/docs.rs [1069:1150]


    fn parses_starlark_function_docstring() {
        let docstring = r#"This is an example docstring

        Details here

        Args:
            arg_foo: The argument named foo
            arg_bar: The argument named bar. It has
                     a longer doc string that spans
                     over three lines
            *args: Docs for args
            **kwargs: Docs for kwargs

        Returns:
            A value
        "#;

        let kind = DocStringKind::Starlark;
        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: "**kwargs".to_owned(),
                    docs: DocString::from_docstring(kind, "Docs for kwargs"),
                    typ: None,
                    default_value: None,
                },
                Param::Arg {
                    name: "*args".to_owned(),
                    docs: DocString::from_docstring(kind, "Docs for args"),
                    typ: None,
                    default_value: None,
                },
                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);
    }