Skip to content

Commit

Permalink
test: reduce integration tests to a single smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Jun 5, 2022
1 parent f1c5456 commit 9f8034d
Showing 1 changed file with 10 additions and 116 deletions.
126 changes: 10 additions & 116 deletions tests/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#[macro_use]
extern crate rstest;

use std::time::Duration;

use bevy::asset::AssetPlugin;
Expand All @@ -9,8 +6,14 @@ use bevy_core::CorePlugin;

use benimator::*;

#[rstest]
fn repeated(mut app: App) {
#[test]
fn plugin_does_not_crash() {
let mut app = App::new();

app.add_plugin(CorePlugin)
.add_plugin(AssetPlugin)
.add_plugin(AnimationPlugin::default());

let animation = app
.world
.get_resource_mut::<Assets<SpriteSheetAnimation>>()
Expand All @@ -20,119 +23,10 @@ fn repeated(mut app: App) {
Duration::from_nanos(0),
));

let entity = app
.world
app.world
.spawn()
.insert_bundle((TextureAtlasSprite::new(0), animation, Play))
.id();

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
1
);
.insert_bundle((TextureAtlasSprite::new(0), animation, Play));

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
2
);

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
0
);
}

#[rstest]
fn run_once(mut app: App) {
let animation = app
.world
.get_resource_mut::<Assets<SpriteSheetAnimation>>()
.unwrap()
.add(SpriteSheetAnimation::from_range(0..=2, Duration::from_nanos(0)).once());

let entity = app
.world
.spawn()
.insert_bundle((TextureAtlasSprite::new(0), animation, Play))
.id();

app.update();
assert!(app.world.get::<Play>(entity).is_some());
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
1
);

app.update();
assert!(app.world.get::<Play>(entity).is_some());
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
2
);

app.update();
assert!(app.world.get::<Play>(entity).is_none());
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
2
);
}

#[rstest]
fn run_ping_pong(mut app: App) {
let animation = app
.world
.get_resource_mut::<Assets<SpriteSheetAnimation>>()
.unwrap()
.add(SpriteSheetAnimation::from_range(0..=2, Duration::from_nanos(0)).ping_pong());

let entity = app
.world
.spawn()
.insert_bundle((TextureAtlasSprite::new(0), animation, Play))
.id();

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
1
);

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
2
);

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
1
);

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
0
);

app.update();
assert_eq!(
app.world.get::<TextureAtlasSprite>(entity).unwrap().index,
1
);
}

#[fixture]
fn app() -> App {
let mut app = App::new();

app.add_plugin(CorePlugin)
.add_plugin(AssetPlugin)
.add_plugin(AnimationPlugin::default());

app
}

0 comments on commit 9f8034d

Please sign in to comment.