Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all of the broken tests #744

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/experimental/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//! clear_background(WHITE);
//! // Now we can draw our character
//! draw_texture_ex(
//! image,
//! &image,
//! 10.,
//! 10.,
//! WHITE,
Expand Down
10 changes: 0 additions & 10 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ impl Font {
/// Sets the [FilterMode](https://docs.rs/miniquad/latest/miniquad/graphics/enum.FilterMode.html#) of this font's texture atlas.
///
/// Use Nearest if you need integer-ratio scaling for pixel art, for example.
///
/// # Example
/// ```
/// # use macroquad::prelude::*;
/// # #[macroquad::main("test")]
/// # async fn main() {
/// let font = Font::default();
/// font.set_filter(FilterMode::Linear);
/// # }
/// ```
pub fn set_filter(&mut self, filter_mode: miniquad::FilterMode) {
self.atlas.lock().unwrap().set_filter(filter_mode);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/coroutine_execution_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use macroquad::{experimental::coroutines::start_coroutine, window::next_frame};

#[macroquad::test]
async fn coroutine_execution_order() {
start_coroutine(async move {
println!("a");
next_frame().await;
println!("b");
});
println!("c");
next_frame().await;
println!("d");
next_frame().await;
}
42 changes: 42 additions & 0 deletions tests/coroutine_manual_poll.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use macroquad::{
experimental::{coroutines::start_coroutine, scene},
window::next_frame,
};

#[macroquad::test]
async fn coroutine_manual_poll() {
struct Player {
state: i32,
}
impl scene::Node for Player {}

let player = scene::add_node(Player { state: 0 });

let mut coroutine = start_coroutine(async move {
loop {
scene::get_node(player).state += 1;
next_frame().await;
}
});

// make sure that coroutine is not yet polled
assert_eq!(scene::get_node(player).state, 0);

coroutine.set_manual_poll();

// still not polled
assert_eq!(scene::get_node(player).state, 0);

coroutine.poll(0.1);
assert_eq!(scene::get_node(player).state, 1);

next_frame().await;
next_frame().await;

// make sure that after main loop's next_frame coroutine was not polled
assert_eq!(scene::get_node(player).state, 1);

// and that we still can poll
coroutine.poll(0.1);
assert_eq!(scene::get_node(player).state, 2);
}
33 changes: 33 additions & 0 deletions tests/coroutine_manual_poll_delay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use macroquad::experimental::{
coroutines::{start_coroutine, wait_seconds},
scene,
};

#[macroquad::test]
async fn coroutine_manual_poll_delay() {
struct Player {
state: i32,
}
impl scene::Node for Player {}

let player = scene::add_node(Player { state: 0 });

let mut coroutine = start_coroutine(async move {
wait_seconds(1.).await;
scene::get_node(player).state = 1;
});

coroutine.set_manual_poll();

assert_eq!(scene::get_node(player).state, 0);

// not 1 second yet, coroutine will have "now": 0.0, "delta": 0.9, (0.0 + 0.9) < 1.0
coroutine.poll(0.9);

assert_eq!(scene::get_node(player).state, 0);

// coroutine will have "now": 0.1, delta: 0.11, (0.9 + 0.11) > 1.0, wait_for_seconds pass
coroutine.poll(0.11);

assert_eq!(scene::get_node(player).state, 1);
}
17 changes: 17 additions & 0 deletions tests/coroutine_memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use macroquad::{experimental::coroutines::start_coroutine, telemetry, window::next_frame};

#[macroquad::test]
async fn coroutine_memory() {
for _ in 0..20 {
start_coroutine(async move {
next_frame().await;
});

next_frame().await;
}

// wait for the last one to finish
next_frame().await;

assert_eq!(telemetry::active_coroutines_count(), 0);
}
87 changes: 0 additions & 87 deletions tests/coroutine_pause.rs

This file was deleted.

22 changes: 2 additions & 20 deletions tests/coroutine_values.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use macroquad::{experimental::coroutines::start_coroutine, telemetry, window::next_frame};
use macroquad::{experimental::coroutines::start_coroutine, window::next_frame};

#[macroquad::test]
async fn coroutine_value() {
async fn coroutine_values() {
let mut coroutine = start_coroutine(async move {
next_frame().await;
1
Expand All @@ -16,21 +16,3 @@ async fn coroutine_value() {

assert_eq!(coroutine.retrieve(), Some(1));
}

#[macroquad::test]
async fn coroutine_memory() {
use macroquad::prelude::*;

for _ in 0..20 {
start_coroutine(async move {
next_frame().await;
});

next_frame().await;
}

// wait for the last one to finish
next_frame().await;

assert_eq!(telemetry::active_coroutines_count(), 0);
}
Loading