add test for custom class name

This commit is contained in:
Nikolay Kim 2017-06-09 12:35:29 -07:00
parent cfb2b16288
commit 5a44ccb40c
2 changed files with 16 additions and 1 deletions

View File

@ -224,6 +224,7 @@ fn parse_attribute(attr: String) -> HashMap<&'static str, syn::Ident> {
let mut params = HashMap::new();
if let Ok(tts) = syn::parse_token_trees(&attr) {
let mut elem = Vec::new();
let mut elems = Vec::new();
for tt in tts.iter() {
@ -232,7 +233,6 @@ fn parse_attribute(attr: String) -> HashMap<&'static str, syn::Ident> {
println!("Wrong format: {:?}", attr.to_string());
}
&syn::TokenTree::Delimited(ref delimited) => {
let mut elem = Vec::new();
for tt in delimited.tts.iter() {
match tt {
&syn::TokenTree::Token(syn::Token::Comma) => {
@ -245,6 +245,9 @@ fn parse_attribute(attr: String) -> HashMap<&'static str, syn::Ident> {
}
}
}
if !elem.is_empty() {
elems.push(elem);
}
for elem in elems {
if elem.len() < 3 {

View File

@ -51,6 +51,18 @@ fn empty_class() {
py_assert!(py, typeobj, "typeobj.__name__ == 'EmptyClass'");
}
#[py::class(name=CustomName)]
struct EmptyClass2 { }
#[test]
fn custom_class_name() {
let gil = Python::acquire_gil();
let py = gil.python();
let typeobj = py.get_type::<EmptyClass2>();
py_assert!(py, typeobj, "typeobj.__name__ == 'CustomName'");
}
#[py::class]
struct EmptyClassInModule { }