mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: more layout tests
This commit is contained in:
parent
0a842b607a
commit
c9b79e76fc
1 changed files with 31 additions and 6 deletions
|
|
@ -1,20 +1,45 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct TestArea(u16, u16);
|
||||
|
||||
impl Widget for TestArea {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Ok(Some([to[0], to[1], self.0, self.1]))
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
self.layout(to.area())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_offset () -> Usually<()> {
|
||||
let area: [u16;4] = [50, 50, 100, 100];
|
||||
assert_eq!(Offset::X(1, "1").layout(area)?, Some([51, 50, 1, 1]));
|
||||
assert_eq!(Offset::Y(1, "1").layout(area)?, Some([50, 51, 1, 1]));
|
||||
assert_eq!(Offset::XY(1, 1, "1").layout(area)?, Some([51, 51, 1, 1]));
|
||||
let test = TestArea(3, 3);
|
||||
assert_eq!(Offset::X(1, test).layout(area)?, Some([51, 50, 3, 3]));
|
||||
assert_eq!(Offset::Y(1, test).layout(area)?, Some([50, 51, 3, 3]));
|
||||
assert_eq!(Offset::XY(1, 1, test).layout(area)?, Some([51, 51, 3, 3]));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_outset () -> Usually<()> {
|
||||
let area: [u16;4] = [50, 50, 100, 100];
|
||||
assert_eq!(Outset::X(1, "1").layout(area)?, Some([49, 50, 3, 1]));
|
||||
assert_eq!(Outset::Y(1, "1").layout(area)?, Some([50, 49, 1, 3]));
|
||||
assert_eq!(Outset::XY(1, 1, "1").layout(area)?, Some([49, 49, 3, 3]));
|
||||
let test = TestArea(3, 3);
|
||||
assert_eq!(Outset::X(1, test).layout(area)?, Some([49, 50, 5, 1]));
|
||||
assert_eq!(Outset::Y(1, test).layout(area)?, Some([50, 49, 1, 5]));
|
||||
assert_eq!(Outset::XY(1, 1, test).layout(area)?, Some([49, 49, 5, 5]));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inset () -> Usually<()> {
|
||||
let area: [u16;4] = [50, 50, 100, 100];
|
||||
let test = TestArea(3, 3);
|
||||
assert_eq!(Inset::X(1, test).layout(area)?, Some([51, 50, 1, 3]));
|
||||
assert_eq!(Inset::Y(1, test).layout(area)?, Some([50, 51, 3, 1]));
|
||||
assert_eq!(Inset::XY(1, 1, test).layout(area)?, Some([51, 51, 1, 1]));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue