test: better, now test fails beside compile ones

This commit is contained in:
same mf who else 2026-02-20 14:36:07 +02:00
parent 2a7e981b9c
commit 5ceceae523
3 changed files with 34 additions and 30 deletions

View file

@ -4,7 +4,7 @@ use crate::*;
/// A point (X, Y).
///
/// ```
/// let xy: XY<u16> = XY(0, 0);
/// let xy = tengri::output::XY(0u16, 0);
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct XY<C: Coord>(
@ -14,7 +14,7 @@ use crate::*;
/// A size (Width, Height).
///
/// ```
/// let wh: WH<u16> = WH(0, 0);
/// let wh = tengri::output::WH(0u16, 0);
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct WH<C: Coord>(
@ -24,7 +24,7 @@ use crate::*;
/// Point with size.
///
/// ```
/// let xywh: XYWH<u16> = XYWH(0, 0, 0, 0);
/// let xywh = tengri::output::XYWH(0u16, 0, 0, 0);
/// ```
///
/// * [ ] TODO: anchor field (determines at which corner/side is X0 Y0)
@ -37,7 +37,7 @@ use crate::*;
/// A cardinal direction.
///
/// ```
/// let direction = Direction::Above;
/// let direction = tengri::output::Direction::Above;
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Copy, Clone, PartialEq, Debug)] pub enum Direction {
@ -47,7 +47,7 @@ use crate::*;
/// 9th of area to place.
///
/// ```
/// let alignment = Align::Center;
/// let alignment = tengri::output::Alignment::Center;
/// ```
#[cfg_attr(test, derive(Arbitrary))]
#[derive(Debug, Copy, Clone, Default)] pub enum Alignment {
@ -57,7 +57,7 @@ use crate::*;
/// A widget that tracks its rendered width and height.
///
/// ```
/// let measure = Measure::default();
/// let measure = tengri::output::Measure::default();
/// ```
#[derive(Default)] pub struct Measure<O: Out> {
pub __: PhantomData<O>,
@ -68,70 +68,76 @@ use crate::*;
/// Show an item only when a condition is true.
///
/// ```
/// let when = When(true, "Yes");
/// let when = tengri::output::when(true, "Yes");
/// ```
pub struct When<O, T>(pub bool, pub T, pub PhantomData<O>);
pub fn when<O, T>(condition: bool, content: T) -> When<O, T> {
When(condition, content, Default::default())
}
/// Show one item if a condition is true and another if the condition is false.
///
/// ```
/// let either = Either(true, "Yes", "No");
/// let either = tengri::output::either(true, "Yes", "No");
/// ```
pub struct Either<E: Out, A, B>(pub bool, pub A, pub B, pub PhantomData<E>);
pub struct Either<E, A, B>(pub bool, pub A, pub B, pub PhantomData<E>);
pub fn either<E, A, B>(condition: bool, content_a: A, content_b: B) -> Either<E, A, B> {
Either(condition, content_a, content_b, Default::default())
}
/// Increment X and/or Y coordinate.
///
/// ```
/// let pushed = Push::XY(2, 2, "Hello");
/// let pushed = tengri::output::Push::XY(2, 2, "Hello");
/// ```
pub enum Push<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Decrement X and/or Y coordinate.
///
/// ```
/// let pulled = Pull::XY(2, 2, "Hello");
/// let pulled = tengri::output::Pull::XY(2, 2, "Hello");
/// ```
pub enum Pull<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the content to fill the container.
///
/// ```
/// let filled = Fill::XY("Hello");
/// let filled = tengri::output::Fill::XY("Hello");
/// ```
pub enum Fill<A> { X(A), Y(A), XY(A) }
/// Set fixed size for content.
///
/// ```
/// let fixed = Fixed::XY(3, 5, "Hello"); // 3x5
/// let fixed = tengri::output::Fixed::XY(3, 5, "Hello"); // 3x5
/// ```
pub enum Fixed<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the maximum width and/or height of the content.
///
/// ```
/// let maximum = Min::XY(3, 5, "Hello"); // 3x1
/// let maximum = tengri::output::Min::XY(3, 5, "Hello"); // 3x1
/// ```
pub enum Max<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Set the minimum width and/or height of the content.
///
/// ```
/// let minimam = Min::XY(3, 5, "Hello"); // 5x5
/// let minimam = tengri::output::Min::XY(3, 5, "Hello"); // 5x5
/// ```
pub enum Min<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Decrease the width and/or height of the content.
///
/// ```
/// let shrunk = Shrink::XY(2, 0, "Hello"); // 1x1
/// let shrunk = tengri::output::Shrink::XY(2, 0, "Hello"); // 1x1
/// ```
pub enum Shrink<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// Increaase the width and/or height of the content.
///
/// ```
/// let expanded = Expand::XY(5, 3, "HELLO"); // 15x3
/// let expanded = tengri::output::Expand::XY(5, 3, "HELLO"); // 15x3
/// ```
pub enum Expand<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
@ -142,7 +148,7 @@ pub enum Expand<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// use ::tengri::{output::*, tui::*};
/// let area = XYWH(10u16, 10, 20, 20);
/// fn test (area: XYWH<16>, item: &impl Draw<TuiOut>, expected: [u16;4]) {
/// assert_eq!(Content::layout(item, area), expected);
/// assert_eq!(Lay::layout(item, area), expected);
/// assert_eq!(Draw::layout(item, area), expected);
/// };
///
@ -174,7 +180,10 @@ pub enum Pad<U, A> { X(U, A), Y(U, A), XY(U, U, A), }
/// TODO DOCUMENTME
///
/// ```
/// let bounded = Bounded(XYWH(0, 0, 0, 0), "");
/// use tengri::output::{Bounded, XYWH};
/// let area = tengri::output::XYWH(0, 0, 0, 0);
/// let content = "";
/// let bounded = tengri::output::Bounded(area, content);
/// ```
pub struct Bounded<O: Out, D>(pub XYWH<O::Unit>, pub D);

View file

@ -3,18 +3,12 @@ use crate::*;
/// Drawing target.
///
/// ```
/// use crate::*;
/// struct TestOut([u16;4]);
/// use tengri::output::*;
/// struct TestOut(XYWH<u16>);
/// 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 area (&self) -> XYWH<u16> { self.0 }
/// fn area_mut (&mut self) -> &mut XYWH<u16> { &mut self.0 }
/// fn place_at <T: Draw<Self> + ?Sized> (&mut self, area: XYWH<u16>, _: &T) {
/// println!("place_at: {area:?}");
/// ()

View file

@ -4,7 +4,8 @@ use crate::*;
//use std::sync::{Arc, RwLock};
struct TestComponent(String);
impl Draw<TuiOut> for TestComponent {
fn draw (&self, _to: &mut TuiOut) {}
fn draw (&self, _to: &mut TuiOut) {
}
}
impl Handle<TuiIn> for TestComponent {
fn handle (&mut self, _from: &TuiIn) -> Perhaps<bool> {