mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
This commit is contained in:
parent
f3fcf663a8
commit
501782f8fe
18 changed files with 841 additions and 908 deletions
|
|
@ -30,76 +30,6 @@ mod widget; pub use self::widget::*;
|
|||
use crate::{*, Direction::*};
|
||||
//use proptest_derive::Arbitrary;
|
||||
use proptest::{prelude::*, option::of};
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_direction (
|
||||
d in prop_oneof![
|
||||
Just(North), Just(South),
|
||||
Just(East), Just(West),
|
||||
Just(Above), Just(Below)
|
||||
],
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
w in u16::MIN..u16::MAX,
|
||||
h in u16::MIN..u16::MAX,
|
||||
a in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let _ = d.split_fixed([x, y, w, h], a);
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_size (
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
a in u16::MIN..u16::MAX,
|
||||
b in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let size = [x, y];
|
||||
let _ = size.w();
|
||||
let _ = size.h();
|
||||
let _ = size.wh();
|
||||
let _ = size.clip_w(a);
|
||||
let _ = size.clip_h(b);
|
||||
let _ = size.expect_min(a, b);
|
||||
let _ = size.to_area_pos();
|
||||
let _ = size.to_area_size();
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_area (
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
w in u16::MIN..u16::MAX,
|
||||
h in u16::MIN..u16::MAX,
|
||||
a in u16::MIN..u16::MAX,
|
||||
b in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::zero();
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::from_position([a, b]);
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::from_size([a, b]);
|
||||
let area: [u16;4] = [x, y, w, h];
|
||||
let _ = area.expect_min(a, b);
|
||||
let _ = area.xy();
|
||||
let _ = area.wh();
|
||||
let _ = area.xywh();
|
||||
let _ = area.clip_h(a);
|
||||
let _ = area.clip_w(b);
|
||||
let _ = area.clip([a, b]);
|
||||
let _ = area.set_w(a);
|
||||
let _ = area.set_h(b);
|
||||
let _ = area.x2();
|
||||
let _ = area.y2();
|
||||
let _ = area.lrtb();
|
||||
let _ = area.center();
|
||||
let _ = area.center_x(a);
|
||||
let _ = area.center_y(b);
|
||||
let _ = area.center_xy([a, b]);
|
||||
let _ = area.centered();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! test_op_transform {
|
||||
($fn:ident, $Op:ident) => {
|
||||
proptest! {
|
||||
|
|
@ -115,7 +45,7 @@ mod widget; pub use self::widget::*;
|
|||
if let Some(op) = match (op_x, op_y) {
|
||||
(Some(x), Some(y)) => Some($Op::XY(x, y, content)),
|
||||
(Some(x), None) => Some($Op::X(x, content)),
|
||||
(None, Some(y)) => Some($Op::y(y, content)),
|
||||
(None, Some(y)) => Some($Op::Y(y, content)),
|
||||
_ => None
|
||||
} {
|
||||
//assert_eq!(Content::layout(&op, [x, y, w, h]),
|
||||
|
|
@ -125,7 +55,6 @@ mod widget; pub use self::widget::*;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
test_op_transform!(proptest_op_fixed, Fixed);
|
||||
test_op_transform!(proptest_op_min, Min);
|
||||
test_op_transform!(proptest_op_max, Max);
|
||||
|
|
@ -157,44 +86,13 @@ mod widget; pub use self::widget::*;
|
|||
}
|
||||
}
|
||||
|
||||
#[test] fn test_stub_output () -> Usually<()> {
|
||||
use crate::*;
|
||||
struct TestOut([u16;4]);
|
||||
impl Out for TestOut {
|
||||
type Unit = u16;
|
||||
type Size = [u16;2];
|
||||
type Area = [u16;4];
|
||||
fn area (&self) -> [u16;4] {
|
||||
self.0
|
||||
}
|
||||
fn area_mut (&mut self) -> &mut [u16;4] {
|
||||
&mut self.0
|
||||
}
|
||||
fn place_at <T: Draw<Self> + ?Sized> (&mut self, area: [u16;4], _: &T) {
|
||||
println!("place_at: {area:?}");
|
||||
()
|
||||
}
|
||||
}
|
||||
impl Draw<TestOut> for String {
|
||||
fn draw (&self, to: &mut TestOut) {
|
||||
to.area_mut().set_w(self.len() as u16);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test] fn test_space () {
|
||||
use crate::*;
|
||||
assert_eq!(Area::center(&[10u16, 10, 20, 20]), [20, 20]);
|
||||
}
|
||||
|
||||
#[test] fn test_iter_map () {
|
||||
struct Foo;
|
||||
impl<T: Out> Content<T> for Foo {}
|
||||
fn _make_map <T: Out, U: Content<T> + Send + Sync> (data: &Vec<U>) -> impl Draw<T> {
|
||||
Map::new(||data.iter(), |_foo, _index|{})
|
||||
}
|
||||
let _data = vec![Foo, Foo, Foo];
|
||||
//let map = make_map(&data);
|
||||
}
|
||||
//#[test] fn test_iter_map () {
|
||||
//struct Foo;
|
||||
//impl<T: Out> Content<T> for Foo {}
|
||||
//fn _make_map <T: Out, U: Content<T> + Send + Sync> (data: &Vec<U>) -> impl Draw<T> {
|
||||
//Map::new(||data.iter(), |_foo, _index|{})
|
||||
//}
|
||||
//let _data = vec![Foo, Foo, Foo];
|
||||
////let map = make_map(&data);
|
||||
//}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue