diff --git a/Cargo.toml b/Cargo.toml index cb8db854e..2c8f2a5f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ authors = [ "Sven-Hendrik Haase ", "Simon Heath ", ] +# TODO: Uncomment this before release? edition = "2018" license = "MIT" readme = "README.md" diff --git a/examples/canvas_subframe.rs b/examples/canvas_subframe.rs index 8f8257f0e..0596b715a 100644 --- a/examples/canvas_subframe.rs +++ b/examples/canvas_subframe.rs @@ -59,12 +59,13 @@ impl MainState { .scale(Vector2::new( ((time % cycle * 2) as f32 / cycle as f32 * 6.28) .cos() - .abs() * 0.0625, + .abs() + * 0.0625, ((time % cycle * 2) as f32 / cycle as f32 * 6.28) .cos() - .abs() * 0.0625, - )) - .rotation(-2.0 * ((time % cycle) as f32 / cycle as f32 * 6.28)); + .abs() + * 0.0625, + )).rotation(-2.0 * ((time % cycle) as f32 / cycle as f32 * 6.28)); self.spritebatch.add(p); } } diff --git a/examples/text.rs b/examples/text.rs index 1f85c0668..034ef8024 100644 --- a/examples/text.rs +++ b/examples/text.rs @@ -62,9 +62,7 @@ impl App { // More fragments can be appended at any time. text.add(" default fragment, should be long enough to showcase everything") // `add()` can be chained, along with most `Text` methods. - .add( - TextFragment::new(" magenta fragment") - .color(Color::new(1.0, 0.0, 1.0, 1.0))) + .add(TextFragment::new(" magenta fragment").color(Color::new(1.0, 0.0, 1.0, 1.0))) .add(" another default fragment, to really drive the point home"); // This loads a new TrueType font into the context and returns a diff --git a/src/graphics/image.rs b/src/graphics/image.rs index c519ce50e..e525c3d25 100644 --- a/src/graphics/image.rs +++ b/src/graphics/image.rs @@ -251,8 +251,7 @@ impl Image { u32::from(self.width), u32::from(self.height), color_format, - ) - .map_err(|e| e.into()), + ).map_err(|e| e.into()), } } diff --git a/src/graphics/spritebatch.rs b/src/graphics/spritebatch.rs index 5443f7fa3..60f03c654 100644 --- a/src/graphics/spritebatch.rs +++ b/src/graphics/spritebatch.rs @@ -100,8 +100,7 @@ impl SpriteBatch { new_param.color = new_param.color; let primitive_param = graphics::DrawTransform::from(new_param); primitive_param.to_instance_properties(ctx.gfx_context.is_srgb()) - }) - .collect::>(); + }).collect::>(); let gfx = &mut ctx.gfx_context; if gfx.data.rect_instance_properties.len() < self.sprites.len() { diff --git a/src/graphics/text.rs b/src/graphics/text.rs index 92aebdc25..77cbf3540 100644 --- a/src/graphics/text.rs +++ b/src/graphics/text.rs @@ -561,8 +561,7 @@ where encoder, &(render_tgt, color_format), &(depth_view, depth_format), - ) - .map_err(|e| GameError::RenderError(e.to_string())) + ).map_err(|e| GameError::RenderError(e.to_string())) } #[cfg(test)] diff --git a/src/input/gamepad.rs b/src/input/gamepad.rs index 20b0ce29e..c7d03a908 100644 --- a/src/input/gamepad.rs +++ b/src/input/gamepad.rs @@ -90,3 +90,14 @@ pub fn axis() { pub fn button_pressed() { unimplemented!() } + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn gilrs_init() { + assert!(GilrsGamepadContext::new().is_ok()); + } +} \ No newline at end of file diff --git a/src/input/keyboard.rs b/src/input/keyboard.rs index 7058e4244..811422216 100644 --- a/src/input/keyboard.rs +++ b/src/input/keyboard.rs @@ -215,8 +215,7 @@ impl KeyboardContext { } else { None } - }) - .collect() + }).collect() } pub(crate) fn active_mods(&self) -> KeyMods { diff --git a/src/input/mouse.rs b/src/input/mouse.rs index 0a222967d..73de88a10 100644 --- a/src/input/mouse.rs +++ b/src/input/mouse.rs @@ -106,8 +106,7 @@ pub fn set_position(ctx: &mut Context, point: Point2) -> GameResult<()> { .set_cursor_position(dpi::LogicalPosition { x: f64::from(point.x), y: f64::from(point.y), - }) - .map_err(|_| GameError::WindowError("Couldn't set mouse cursor position!".to_owned())) + }).map_err(|_| GameError::WindowError("Couldn't set mouse cursor position!".to_owned())) } /// Get the distance the cursor was moved during last frame, in pixels. diff --git a/src/vfs.rs b/src/vfs.rs index 592504a84..b6399e649 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -553,8 +553,7 @@ impl ZipFS { .expect("Should never happen!") .name() .to_string() - }) - .collect(); + }).collect(); Ok(Self { source: filename.into(), archive: RefCell::new(archive), diff --git a/tests/screenshot.rs b/tests/screenshot.rs new file mode 100644 index 000000000..1f7191bce --- /dev/null +++ b/tests/screenshot.rs @@ -0,0 +1,32 @@ + +extern crate ggez; +use ggez::*; + +use std::env; +use std::path; + +// TODO: Is there a good way to dedupe this? +fn make_context() -> (Context, event::EventsLoop) { + let mut cb = ContextBuilder::new("ggez_unit_tests", "ggez"); + if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { + let mut path = path::PathBuf::from(manifest_dir); + path.push("resources"); + cb = cb.add_resource_path(path); + } + cb.build().unwrap() +} + +#[test] +fn image_encode() { + let (c, _e) = &mut make_context(); + let image = graphics::Image::new(c, "/player.png").unwrap(); + image.encode(c, graphics::ImageFormat::Png, "/encode_test.png").unwrap(); +} + + +#[test] +fn save_screenshot() { + let (c, _e) = &mut make_context(); + let screenshot = graphics::screenshot(c).unwrap(); + // screenshot.encode(c, graphics::ImageFormat::Png, "/screenshot_test.png").unwrap(); +} \ No newline at end of file diff --git a/tests/text.rs b/tests/text.rs index 2e9514848..e233fe173 100644 --- a/tests/text.rs +++ b/tests/text.rs @@ -12,7 +12,6 @@ fn make_context() -> (Context, event::EventsLoop) { path.push("resources"); cb = cb.add_resource_path(path); } - cb.build().unwrap() } /* TODO; the font API has changed and I don't want to deal with it now