Skip to content

Commit ce56888

Browse files
authored
test: add unit test in derive-impl verifying path-qualified py attrs return an error
1 parent c8b18a5 commit ce56888

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎crates/derive-impl/src/pyclass.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,3 +2073,27 @@ fn parse_vec_ident(
20732073
})?
20742074
.to_string())
20752075
}
2076+
2077+
#[cfg(test)]
2078+
mod tests {
2079+
use super::*;
2080+
2081+
// Regression test: path-qualified inner attrs like `#[vm::pymethod]` must return an error.
2082+
// Before the fix, `attrs_to_content_items` looped forever on such attributes.
2083+
#[test]
2084+
fn path_qualified_py_attr_returns_error() {
2085+
let attr: syn::Attribute = syn::parse_quote!(#[vm::pymethod]);
2086+
let result =
2087+
attrs_to_content_items(&[attr], |i, name| (i, name));
2088+
let err = result.expect_err("expected error for path-qualified #[vm::pymethod]");
2089+
let msg = err.to_string();
2090+
assert!(
2091+
msg.contains("vm::pymethod"),
2092+
"error should mention the full path; got: {msg}"
2093+
);
2094+
assert!(
2095+
msg.contains("pymethod"),
2096+
"error should mention the unqualified name; got: {msg}"
2097+
);
2098+
}
2099+
}

0 commit comments

Comments
 (0)