-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path_view_state_test.v
More file actions
65 lines (54 loc) · 1.44 KB
/
Copy path_view_state_test.v
File metadata and controls
65 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module gui
import os
import time
fn test_clear_view_state_clears_diagram_cache_temp_files() {
tmp_path := os.join_path(os.temp_dir(), 'gui_diagram_test_${time.now().unix_micro()}.png')
os.write_file(tmp_path, 'x') or { panic(err) }
defer {
if os.exists(tmp_path) {
os.rm(tmp_path) or {}
}
}
mut w := Window{}
w.view_state.diagram_cache.set(1, DiagramCacheEntry{
state: .ready
png_path: tmp_path
})
assert os.exists(tmp_path)
w.clear_view_state()
assert !os.exists(tmp_path)
assert w.view_state.diagram_cache.len() == 0
}
fn test_bounded_image_map_fifo_eviction() {
mut w := Window{}
mut ctx := w.context()
mut m := BoundedImageMap{
max_size: 2
}
m.set('a', 1, mut ctx)
m.set('b', 2, mut ctx)
assert m.len() == 2
assert m.keys() == ['a', 'b']
// Adding 'c' should evict 'a' (FIFO)
m.set('c', 3, mut ctx)
assert m.len() == 2
assert m.get('a') == none
assert m.get('b') or { -1 } == 2
assert m.get('c') or { -1 } == 3
assert m.keys() == ['b', 'c']
// Deleting 'b' and adding 'd'
m.delete('b')
assert m.len() == 1
m.set('d', 4, mut ctx)
assert m.len() == 2
assert m.keys() == ['c', 'd']
}
fn test_state_registry_clear_drops_maps() {
mut w := Window{}
_ = state_map[string, int](mut w, 'test.a', 10)
_ = state_map[string, bool](mut w, 'test.b', 10)
assert w.view_state.registry.maps.len == 2
w.view_state.registry.clear()
assert w.view_state.registry.maps.len == 0
assert w.view_state.registry.meta.len == 0
}