Skip to content

Commit

Permalink
Update caching tests to use tree 100 nodes deep (relax permitted meas…
Browse files Browse the repository at this point in the history
…ure count to 7)
  • Loading branch information
nicoburns committed Mar 20, 2023
1 parent dacf2c1 commit 72674ea
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod caching {
let mut taffy = Taffy::new();
static NUM_MEASURES: AtomicU32 = AtomicU32::new(0);

let grandchild = taffy
let leaf = taffy
.new_leaf_with_measure(
Style { ..Default::default() },
MeasureFunc::Raw(|known_dimensions, _available_space| {
Expand All @@ -23,12 +23,14 @@ mod caching {
)
.unwrap();

let child = taffy.new_with_children(Style::DEFAULT, &[grandchild]).unwrap();
let mut node = taffy.new_with_children(Style::DEFAULT, &[leaf]).unwrap();
for _ in 0..100 {
node = taffy.new_with_children(Style::DEFAULT, &[node]).unwrap();
}

let node = taffy.new_with_children(Style::DEFAULT, &[child]).unwrap();
taffy.compute_layout(node, Size::MAX_CONTENT).unwrap();

assert_eq!(NUM_MEASURES.load(Ordering::SeqCst), 2);
assert_eq!(NUM_MEASURES.load(Ordering::SeqCst), 7);
}

#[test]
Expand All @@ -41,7 +43,7 @@ mod caching {
let mut taffy = Taffy::new();
static NUM_MEASURES: AtomicU32 = AtomicU32::new(0);

let grandchild = taffy
let leaf = taffy
.new_leaf_with_measure(
style(),
MeasureFunc::Raw(|known_dimensions, _available_space| {
Expand All @@ -54,11 +56,12 @@ mod caching {
)
.unwrap();

let child = taffy.new_with_children(style(), &[grandchild]).unwrap();

let node = taffy.new_with_children(style(), &[child]).unwrap();
let mut node = taffy.new_with_children(Style::DEFAULT, &[leaf]).unwrap();
for _ in 0..100 {
node = taffy.new_with_children(Style::DEFAULT, &[node]).unwrap();
}

taffy.compute_layout(node, Size::MAX_CONTENT).unwrap();
assert_eq!(NUM_MEASURES.load(Ordering::SeqCst), 2);
assert_eq!(NUM_MEASURES.load(Ordering::SeqCst), 7);
}
}

0 comments on commit 72674ea

Please sign in to comment.