#![cfg(feature = "derive")]
use to_values::ToInputVector;
#[derive(ToInputVector)]
struct Position {
x: f32,
y: f32,
}
#[derive(ToInputVector)]
struct Entity {
position: Position,
#[input(skip)]
id: String,
money: f32,
}
#[derive(ToInputVector)]
#[allow(dead_code)]
struct TupleEntity(f32, #[input(skip)] String, bool);
#[derive(ToInputVector)]
struct Generic<T>
where
T: Clone,
{
value: T,
}
#[derive(ToInputVector)]
struct Empty;
#[test]
fn derive_flattens_fields_and_honours_skips() {
let entity = Entity {
position: Position { x: 1.5, y: -2.0 },
id: "entity-42".to_owned(),
money: 10.0,
};
assert_eq!(entity.id, "entity-42");
assert_eq!(entity.input_vector_len(), 3);
assert_eq!(entity.to_input_vector(), vec![1.5, -2.0, 10.0]);
}
#[test]
fn derive_supports_tuple_unit_and_generic_structs() {
assert_eq!(
TupleEntity(2.0, "ignored".to_owned(), true).to_input_vector(),
vec![2.0, 1.0]
);
assert!(Empty.to_input_vector().is_empty());
assert_eq!(Generic { value: 7_u8 }.to_input_vector(), vec![7.0]);
}