Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Jun 4, 2022
1 parent 97ac8b1 commit ed7219b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 44 deletions.
10 changes: 0 additions & 10 deletions crates/bevy_reflect/src/enums/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ pub fn enum_hash<TEnum: Enum>(value: &TEnum) -> Option<u64> {
Some(hasher.finish())
}

// TODO: Add serializable. How do we handle enums?
// pub fn enum_serialize<TEnum, S>(value: &TEnum, serializer: S) -> Result<S::Ok, S::Error>
// where
// TEnum: Enum + ?Sized,
// S: serde::Serializer,
// {
//
//
// }

/// Compares an [`Enum`] with a [`Reflect`] value.
///
/// Returns true if and only if all of the following are true:
Expand Down
82 changes: 48 additions & 34 deletions crates/bevy_reflect/src/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,58 +445,72 @@ mod tests {

let a: &dyn Reflect = &TestEnum::A;
let b: &dyn Reflect = &TestEnum::A;
assert!(a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::A == TestEnum::A");
assert!(
a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::A == TestEnum::A"
);

let a: &dyn Reflect = &TestEnum::A;
let b: &dyn Reflect = &TestEnum::A1;
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::A != TestEnum::A1");
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::A != TestEnum::A1"
);

let a: &dyn Reflect = &TestEnum::B(123);
let b: &dyn Reflect = &TestEnum::B(123);
assert!(a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) == TestEnum::B(123)");
assert!(
a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::B(123) == TestEnum::B(123)"
);

let a: &dyn Reflect = &TestEnum::B(123);
let b: &dyn Reflect = &TestEnum::B(321);
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B(321)");
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::B(123) != TestEnum::B(321)"
);

let a: &dyn Reflect = &TestEnum::B(123);
let b: &dyn Reflect = &TestEnum::B1(123);
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B1(123)");
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::B(123) != TestEnum::B1(123)"
);

let a: &dyn Reflect = &TestEnum::B(123);
let b: &dyn Reflect = &TestEnum::B2(123, 123);
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::B(123) != TestEnum::B2(123, 123)");
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::B(123) != TestEnum::B2(123, 123)"
);

let a: &dyn Reflect = &TestEnum::C {
value: 123
};
let b: &dyn Reflect = &TestEnum::C {
value: 123
};
assert!(a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} == TestEnum::C{{value: 123}}");
let a: &dyn Reflect = &TestEnum::C { value: 123 };
let b: &dyn Reflect = &TestEnum::C { value: 123 };
assert!(
a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::C{{value: 123}} == TestEnum::C{{value: 123}}"
);

let a: &dyn Reflect = &TestEnum::C {
value: 123
};
let b: &dyn Reflect = &TestEnum::C {
value: 321
};
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C{{value: 321}}");
let a: &dyn Reflect = &TestEnum::C { value: 123 };
let b: &dyn Reflect = &TestEnum::C { value: 321 };
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::C{{value: 123}} != TestEnum::C{{value: 321}}"
);

let a: &dyn Reflect = &TestEnum::C {
value: 123
};
let b: &dyn Reflect = &TestEnum::C1 {
value: 123
};
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C1{{value: 123}}");
let a: &dyn Reflect = &TestEnum::C { value: 123 };
let b: &dyn Reflect = &TestEnum::C1 { value: 123 };
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::C{{value: 123}} != TestEnum::C1{{value: 123}}"
);

let a: &dyn Reflect = &TestEnum::C {
value: 123
};
let b: &dyn Reflect = &TestEnum::C2 {
value: 1.23
};
assert!(!a.reflect_partial_eq(b).unwrap_or_default(), "expected TestEnum::C{{value: 123}} != TestEnum::C2{{value: 1.23}}");
let a: &dyn Reflect = &TestEnum::C { value: 123 };
let b: &dyn Reflect = &TestEnum::C2 { value: 1.23 };
assert!(
!a.reflect_partial_eq(b).unwrap_or_default(),
"expected TestEnum::C{{value: 123}} != TestEnum::C2{{value: 1.23}}"
);
}
}

0 comments on commit ed7219b

Please sign in to comment.