Compare regions, not four loose numbers
`PixelRegion` derives `PartialEq`, `Clone` and `Copy`, so `assert_corners!` compares one against another instead of flattening both to a tuple whose order there was nothing to check. A failure now prints two regions.
This commit is contained in:
1 parent
0f9f379cec
commit
7cefc72f97
2 files changed
+9
-13
No files matched your search
@@ -421,7 +421,7 @@ impl Display for UiRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct PixelRegion {
|
pub struct PixelRegion {
|
||||||
pub top_left: Vec2,
|
pub top_left: Vec2,
|
||||||
pub bot_right: Vec2,
|
pub bot_right: Vec2,
|
||||||
|
|||||||
+8
-12
@@ -22,22 +22,18 @@ impl TaskQueue<DefaultRsc<HarnessState>> for Queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `assert_eq!` for where a frame put a widget, which `PixelRegion` cannot do
|
/// `assert_eq!` for where a frame put a widget, written as its two corners.
|
||||||
/// for itself: it neither compares nor prints.
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! assert_corners {
|
macro_rules! assert_corners {
|
||||||
($harness:expr, $id:expr, ($x0:expr, $y0:expr), ($x1:expr, $y1:expr)) => {{
|
($harness:expr, $id:expr, ($x0:expr, $y0:expr), ($x1:expr, $y1:expr)) => {
|
||||||
let region = $harness.region(&$id).expect("widget drew nothing");
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(
|
$harness.region(&$id).expect("widget drew nothing"),
|
||||||
region.top_left.x,
|
$crate::core::PixelRegion {
|
||||||
region.top_left.y,
|
top_left: $crate::core::util::Vec2::new($x0 as f32, $y0 as f32),
|
||||||
region.bot_right.x,
|
bot_right: $crate::core::util::Vec2::new($x1 as f32, $y1 as f32),
|
||||||
region.bot_right.y
|
}
|
||||||
),
|
|
||||||
($x0 as f32, $y0 as f32, $x1 as f32, $y1 as f32)
|
|
||||||
);
|
);
|
||||||
}};
|
};
|
||||||
}
|
}
|
||||||
pub use crate::assert_corners;
|
pub use crate::assert_corners;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user