Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Oct 15, 2023
1 parent 2cfc46a commit 736dda1
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions crates/torin/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,119 @@ pub fn margin() {
Rect::new(Point2D::new(5.0, 5.0), Size2D::new(200.0, 200.0)),
);
}

#[test]
pub fn double_center_alignment() {
let (mut layout, mut measurer) = test_utils();

let mut mocked_dom = TestingDOM::default();
mocked_dom.add(
0,
None,
vec![1],
Node::from_size_and_alignments_and_direction(
Size::Percentage(Length::new(100.0)),
Size::Percentage(Length::new(100.0)),
Alignment::Center,
Alignment::Center,
DirectionMode::Vertical,
),
);
mocked_dom.add(
1,
Some(0),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(200.0)),
Size::Pixels(Length::new(200.0)),
DirectionMode::Vertical,
),
);
mocked_dom.add(
2,
Some(0),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(300.0)),
Size::Pixels(Length::new(300.0)),
DirectionMode::Vertical,
),
);

layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
);

let node_areas = layout.get(1).unwrap();

assert_eq!(
node_areas.area,
Rect::new(Point2D::new(250.0, 250.0), Size2D::new(200.0, 200.0)),
);

assert_eq!(
node_areas.box_area(),
Rect::new(Point2D::new(450.0, 450.0), Size2D::new(300.0, 300.0)),
);
}

#[test]
pub fn double_end_alignment() {
let (mut layout, mut measurer) = test_utils();

let mut mocked_dom = TestingDOM::default();
mocked_dom.add(
0,
None,
vec![1],
Node::from_size_and_alignments_and_direction(
Size::Percentage(Length::new(100.0)),
Size::Percentage(Length::new(100.0)),
Alignment::End,
Alignment::End,
DirectionMode::Vertical,
),
);
mocked_dom.add(
1,
Some(0),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(200.0)),
Size::Pixels(Length::new(200.0)),
DirectionMode::Vertical,
),
);
mocked_dom.add(
2,
Some(0),
vec![],
Node::from_size_and_direction(
Size::Pixels(Length::new(300.0)),
Size::Pixels(Length::new(300.0)),
DirectionMode::Vertical,
),
);

layout.measure(
0,
Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)),
&mut measurer,
&mut mocked_dom,
);

let node_areas = layout.get(1).unwrap();

assert_eq!(
node_areas.area,
Rect::new(Point2D::new(500.0, 500.0), Size2D::new(200.0, 200.0)),
);

assert_eq!(
node_areas.box_area(),
Rect::new(Point2D::new(700.0, 700.0), Size2D::new(300.0, 300.0)),
);
}

0 comments on commit 736dda1

Please sign in to comment.