Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-core/src/presenter_tests.rs
StratoSDK / crates / strato-ui-core / src / presenter_tests.rs
1use crate::presenter::PositionCache;
2use pathfinder_geometry::rect::RectF;
3use pathfinder_geometry::vector::Vector2F;
4 
5#[test]
6fn test_position_cache_caching() {
7 let mut position_cache = PositionCache::new();
8 position_cache.start();
9 
10 position_cache.cache_position_indefinitely(
11 "position_1".to_string(),
12 RectF::new(Vector2F::zero(), Vector2F::new(100.0, 100.0)),
13 );
14 position_cache.cache_position_for_one_frame(
15 "position_2".to_string(),
16 RectF::new(Vector2F::zero(), Vector2F::new(50.0, 50.0)),
17 );
18 
19 position_cache.start();
20 position_cache.cache_position_indefinitely(
21 "position_1".to_string(),
22 RectF::new(Vector2F::zero(), Vector2F::new(25.0, 25.0)),
23 );
24 position_cache.cache_position_indefinitely(
25 "position_2".to_string(),
26 RectF::new(Vector2F::zero(), Vector2F::new(10.0, 10.0)),
27 );
28 position_cache.cache_position_for_one_frame(
29 "position_3".to_string(),
30 RectF::new(Vector2F::zero(), Vector2F::new(5.0, 5.0)),
31 );
32 assert_eq!(position_cache.get_position("position_1"), None);
33 
34 position_cache.end();
35 assert_eq!(
36 position_cache.get_position("position_1"),
37 Some(RectF::new(Vector2F::zero(), Vector2F::new(25.0, 25.0)))
38 );
39 assert_eq!(
40 position_cache.get_position("position_2"),
41 Some(RectF::new(Vector2F::zero(), Vector2F::new(10.0, 10.0)))
42 );
43 assert_eq!(
44 position_cache.get_position("position_3"),
45 Some(RectF::new(Vector2F::zero(), Vector2F::new(5.0, 5.0)))
46 );
47 
48 position_cache.end();
49 assert_eq!(
50 position_cache.get_position("position_1"),
51 Some(RectF::new(Vector2F::zero(), Vector2F::new(100.0, 100.0)))
52 );
53 assert_eq!(
54 position_cache.get_position("position_2"),
55 Some(RectF::new(Vector2F::zero(), Vector2F::new(50.0, 50.0)))
56 );
57 assert_eq!(
58 position_cache.get_position("position_3"),
59 Some(RectF::new(Vector2F::zero(), Vector2F::new(5.0, 5.0)))
60 );
61 
62 position_cache.clear_single_frame_positions();
63 assert_eq!(
64 position_cache.get_position("position_1"),
65 Some(RectF::new(Vector2F::zero(), Vector2F::new(100.0, 100.0)))
66 );
67 assert_eq!(
68 position_cache.get_position("position_2"),
69 Some(RectF::new(Vector2F::zero(), Vector2F::new(50.0, 50.0)))
70 );
71 assert_eq!(position_cache.get_position("position_3"), None);
72 
73 position_cache.clear_position("position_1");
74 assert_eq!(position_cache.get_position("position_1"), None);
75}
76