From 09288a40e7dd5d14921b2279e421e9a6a75389c2 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Sat, 31 Dec 2022 17:09:23 -0800 Subject: [PATCH] Add tests for SceneFilter --- crates/bevy_scene/src/scene_filter.rs | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/crates/bevy_scene/src/scene_filter.rs b/crates/bevy_scene/src/scene_filter.rs index e614bbc5ddc2f..b4a923ac3037e 100644 --- a/crates/bevy_scene/src/scene_filter.rs +++ b/crates/bevy_scene/src/scene_filter.rs @@ -168,3 +168,55 @@ impl IntoIterator for SceneFilter { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn should_set_list_type_if_none() { + let mut filter = SceneFilter::None; + filter.allow::(); + assert!(matches!(filter, SceneFilter::Allowlist(_))); + + let mut filter = SceneFilter::None; + filter.deny::(); + assert!(matches!(filter, SceneFilter::Denylist(_))); + } + + #[test] + fn should_add_to_list() { + let mut filter = SceneFilter::default(); + filter.allow::(); + filter.allow::(); + assert_eq!(2, filter.len()); + assert!(filter.is_allowed::()); + assert!(filter.is_allowed::()); + + let mut filter = SceneFilter::default(); + filter.deny::(); + filter.deny::(); + assert_eq!(2, filter.len()); + assert!(filter.is_denied::()); + assert!(filter.is_denied::()); + } + + #[test] + fn should_remove_from_list() { + let mut filter = SceneFilter::default(); + filter.allow::(); + filter.allow::(); + filter.deny::(); + assert_eq!(1, filter.len()); + assert!(filter.is_allowed::()); + assert!(!filter.is_allowed::()); + + let mut filter = SceneFilter::default(); + filter.deny::(); + filter.deny::(); + filter.allow::(); + assert_eq!(1, filter.len()); + assert!(filter.is_denied::()); + assert!(!filter.is_denied::()); + } +}