Skip to content

Commit

Permalink
Add FromReflect default attr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed May 9, 2022
1 parent 028c684 commit d4d0369
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,34 @@ mod tests {
std::any::type_name::<TestTupleStruct>()
);
}

#[test]
fn from_reflect_should_use_default_attributes() {
#[derive(Reflect, FromReflect, Eq, PartialEq, Debug)]
struct MyStruct {
// Use `Default::default()`
// Note that this isn't an ignored field
#[reflect(default)]
foo: String,

// Use `get_foo_default()`
#[reflect(default = "get_bar_default")]
#[reflect(ignore)]
bar: usize,
}

fn get_bar_default() -> usize {
123
}

let expected = MyStruct {
foo: String::default(),
bar: 123,
};

let dyn_struct = DynamicStruct::default();
let my_struct = <MyStruct as FromReflect>::from_reflect(&dyn_struct);

assert_eq!(Some(expected), my_struct);
}
}

0 comments on commit d4d0369

Please sign in to comment.