1#![forbid(unsafe_code)]
2#![warn(missing_docs)]
3#![cfg_attr(
4 not(test),
5 deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)
6)]
7
8use quote::quote;
9use syn::DeriveInput;
10
11pub fn impl_skill_derive(input: &DeriveInput) -> proc_macro2::TokenStream {
12 let name = &input.ident;
13 let name_str = name.to_string().to_lowercase().replace('_', "-");
14
15 quote! {
16 impl #name {
17 pub fn skill_name() -> &'static str {
19 #name_str
20 }
21 }
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28 use syn::parse_quote;
29
30 #[test]
31 fn test_skill_name_generation() {
32 let input: DeriveInput = parse_quote! { struct My_Skill; };
33 let res = impl_skill_derive(&input).to_string();
34 assert!(res.contains("\"my-skill\""));
35 }
36}