use std::{
fmt::Debug,
ops::{Deref, DerefMut},
};
use bevy::prelude::*;
#[derive(Default)]
pub struct AppTest {
app: App,
}
impl AppTest {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn assert_state<S: States>(&self, s: &S) {
self.assert_state_r(s).unwrap();
}
pub fn assert_state_r<S: States + Debug>(&self, s: &S) -> Result<(), String> {
let app_state = self
.app
.world()
.get_resource::<State<S>>()
.ok_or("State not found".to_string())?
.get();
if app_state != s {
return Err(format!("State was not equal: {app_state:?} != {s:?}"));
}
Ok(())
}
}
impl From<App> for AppTest {
fn from(value: App) -> Self {
Self { app: value }
}
}
impl Deref for AppTest {
type Target = App;
fn deref(&self) -> &Self::Target {
&self.app
}
}
impl DerefMut for AppTest {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.app
}
}