add tests for the api
This commit is contained in:
@@ -15,5 +15,5 @@ quote = { workspace = true }
|
||||
syn = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = { workspace = true }
|
||||
api = { path = "../api" }
|
||||
trybuild = { workspace = true }
|
||||
|
||||
@@ -70,10 +70,7 @@ pub fn derive_into_command_definition_impl(
|
||||
});
|
||||
quote! { #(#field_entries)* }
|
||||
}
|
||||
Fields::Unnamed(fields) => abort!(
|
||||
fields,
|
||||
"IntoCommandDefinition not supported for unnamed structs"
|
||||
),
|
||||
Fields::Unnamed(_) => unreachable!("Already checked this"),
|
||||
Fields::Unit => quote! {},
|
||||
};
|
||||
let param_name_stream = match &data.fields {
|
||||
@@ -84,10 +81,7 @@ pub fn derive_into_command_definition_impl(
|
||||
});
|
||||
quote! { #(#field_entries)* }
|
||||
}
|
||||
Fields::Unnamed(fields) => abort!(
|
||||
fields,
|
||||
"IntoCommandDefinition not supported for unnamed structs"
|
||||
),
|
||||
Fields::Unnamed(_) => unreachable!("Already checked this"),
|
||||
Fields::Unit => quote! {},
|
||||
};
|
||||
|
||||
|
||||
@@ -149,3 +149,22 @@ fn test_generic_command() {
|
||||
.unwrap();
|
||||
assert_eq!(result.a, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unit_command() {
|
||||
#[derive(IntoCommandDefinition)]
|
||||
struct TestStruct;
|
||||
|
||||
let command_definition = TestStruct::create("Test".to_string());
|
||||
|
||||
assert_eq!(command_definition.name, "Test");
|
||||
assert_eq!(command_definition.parameters.capacity(), 0);
|
||||
|
||||
TestStruct::parse(Command {
|
||||
header: CommandHeader {
|
||||
timestamp: Default::default(),
|
||||
},
|
||||
parameters: HashMap::new(),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user