what is up with those tests!

This commit is contained in:
🪞👃🪞 2025-01-09 22:28:23 +01:00
parent 01835c8077
commit 7ddb95d521
6 changed files with 87 additions and 88 deletions

View file

@ -35,23 +35,55 @@ pub type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type.
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
#[cfg(test)] #[test] fn test_stub_output () -> Usually<()> {
use crate::*;
struct TestOutput([u16;4]);
impl Output for TestOutput {
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 (&mut self, _: [u16;4], _: &impl Render<TestOutput>) {
()
}
}
impl Content<TestOutput> for String {
fn render (&self, to: &mut TestOutput) {
to.area_mut().set_w(self.len() as u16);
}
}
Ok(())
}
#[cfg(test)] #[test] fn test_dimensions () {
use crate::*;
assert_eq!(Area::center(&[10u16, 10, 20, 20]), [20, 20]);
}
#[cfg(test)] #[test] fn test_layout () -> Usually<()> {
use ::tek_tui::Tui;
use ::tek_tui::{*, tek_output::*};
let area: [u16;4] = [10, 10, 20, 20];
let unit = ();
assert_eq!(Content::<TuiOut>::layout(&unit, area), [20, 20, 0, 0]);
assert_eq!(Fill::<TuiOut>::x(unit).layout(area), [10, 20, 20, 0]);
assert_eq!(Fill::<TuiOut>::y(unit).layout(area), [20, 10, 0, 20]);
assert_eq!(Fill::<TuiOut>::xy(unit).layout(area), area);
assert_eq!(Content::<TuiOut>::layout(&Fill::<()>::x(unit), area), [10, 20, 20, 0]);
assert_eq!(Render::<TuiOut>::layout(&Fill::<()>::x(unit), area), [10, 20, 20, 0]);
assert_eq!(Fill::<()>::y(unit).layout(area), [20, 10, 0, 20]);
assert_eq!(Fill::<()>::xy(unit).layout(area), area);
assert_eq!(Fixed::<TuiOut, u16>::x(4, unit).layout(area), [18, 20, 4, 0]);
assert_eq!(Fixed::<TuiOut, u16>::y(4, unit).layout(area), [20, 18, 0, 4]);
assert_eq!(Fixed::<TuiOut, u16>::xy(4, 4, unit).layout(area), [18, 18, 4, 4]);
let four = ||Fixed::<TuiOut>::xy(4, 4, unit);
let four = ||Fixed::<TuiOut, _>::xy(4, 4, unit);
assert_eq!(Align::nw(four()).layout(area), [10, 10, 4, 4]);
assert_eq!(Align::n(four()).layout(area), [18, 10, 4, 4]);
@ -62,7 +94,7 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
assert_eq!(Align::sw(four()).layout(area), [10, 26, 4, 4]);
assert_eq!(Align::w(four()).layout(area), [10, 18, 4, 4]);
let two_by_four = ||Fixed::<TuiOut>::xy(4, 2, unit);
let two_by_four = ||Fixed::<TuiOut, _>::xy(4, 2, unit);
assert_eq!(Align::nw(two_by_four()).layout(area), [10, 10, 4, 2]);
assert_eq!(Align::n(two_by_four()).layout(area), [18, 10, 4, 2]);