doc string should not contain /// (#32)

This commit is contained in:
messense 2017-06-13 12:15:44 +08:00 committed by GitHub
parent 7379766ea8
commit d6979c8556
2 changed files with 15 additions and 5 deletions

View file

@ -21,7 +21,15 @@ pub fn get_doc(attrs: &Vec<syn::Attribute>) -> syn::Lit {
syn::MetaItem::NameValue(ref ident, ref lit) => {
if ident.as_ref() == "doc" {
let s = quote!{ #lit }.to_string();
doc.push(s[1..s.len()-1].to_owned())
let mut s = s[1..s.len()-1].to_string();
if s.starts_with("/// ") {
// Remove leading whitespace and ///
s = s[4..].to_string();
} else {
// Remove only ///
s = s[3..].to_string();
}
doc.push(s)
}
}
_ => (),

View file

@ -51,9 +51,11 @@ fn empty_class() {
py_assert!(py, typeobj, "typeobj.__name__ == 'EmptyClass'");
}
#[py::class]
/// Line1
/// Line2
///Line2
/// Line3
// this is not doc string
#[py::class]
struct ClassWithDocs { }
#[test]
@ -61,7 +63,7 @@ fn class_with_docstr() {
let gil = Python::acquire_gil();
let py = gil.python();
let typeobj = py.get_type::<ClassWithDocs>();
py_run!(py, typeobj, "assert typeobj.__doc__ == '/// Line1\\n/// Line2'");
py_run!(py, typeobj, "assert typeobj.__doc__ == 'Line1\\nLine2\\n Line3'");
}
#[py::class(name=CustomName)]
@ -255,7 +257,7 @@ fn instance_method() {
let d = PyDict::new(py);
d.set_item(py, "obj", obj).unwrap();
py.run("assert obj.method() == 42", None, Some(&d)).unwrap();
py.run("assert obj.method.__doc__ == '/// Test method'", None, Some(&d)).unwrap();
py.run("assert obj.method.__doc__ == 'Test method'", None, Some(&d)).unwrap();
}
#[py::class]