More correct caching logic (#911)
1#[cfg(test)]
2mod caching {
3 use taffy::prelude::*;
4 use taffy_test_helpers::{new_test_tree, test_measure_function, TestNodeContext};
5
6 const NODE_CONTEXT: TestNodeContext = TestNodeContext::fixed(50.0, 50.0);
7
8 #[test]
9 fn measure_count_flexbox() {
10 let mut taffy = new_test_tree();
11
12 let leaf = taffy.new_leaf_with_context(Style::default(), NODE_CONTEXT).unwrap();
13
14 let mut node = taffy.new_with_children(Style::DEFAULT, &[leaf]).unwrap();
15 for _ in 0..100 {
16 node = taffy.new_with_children(Style::DEFAULT, &[node]).unwrap();
17 }
18
19 taffy.compute_layout_with_measure(node, Size::MAX_CONTENT, test_measure_function).unwrap();
20
21 assert_eq!(taffy.get_node_context_mut(leaf).unwrap().count, 7);
22 }
23
24 #[test]
25 #[cfg(feature = "grid")]
26 fn measure_count_grid() {
27 let mut taffy = new_test_tree();
28
29 let style = || Style { display: Display::Grid, ..Default::default() };
30 let leaf = taffy.new_leaf_with_context(style(), NODE_CONTEXT).unwrap();
31
32 let mut node = taffy.new_with_children(Style::DEFAULT, &[leaf]).unwrap();
33 for _ in 0..100 {
34 node = taffy.new_with_children(Style::DEFAULT, &[node]).unwrap();
35 }
36
37 taffy.compute_layout_with_measure(node, Size::MAX_CONTENT, test_measure_function).unwrap();
38 assert_eq!(taffy.get_node_context_mut(leaf).unwrap().count, 7);
39 }
40}