-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path_layout_query_test.v
More file actions
86 lines (83 loc) · 1.49 KB
/
_layout_query_test.v
File metadata and controls
86 lines (83 loc) · 1.49 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module gui
fn test_collect_focus_candidates_dedupes_first_seen() {
s1 := &Shape{
id_focus: 9
}
s2 := &Shape{
id_focus: 9
}
root := Layout{
shape: &Shape{}
children: [
Layout{
shape: s1
},
Layout{
shape: s2
},
]
}
mut candidates := []FocusCandidate{}
mut seen := map[u32]bool{}
collect_focus_candidates(&root, mut candidates, mut seen)
assert candidates.len == 1
assert candidates[0].id == 9
}
fn test_focus_find_next_by_id_without_sort() {
s1 := &Shape{
id_focus: 30
}
s2 := &Shape{
id_focus: 10
}
s3 := &Shape{
id_focus: 40
}
candidates := [
FocusCandidate{
id: 30
shape: s1
},
FocusCandidate{
id: 10
shape: s2
},
FocusCandidate{
id: 40
shape: s3
},
]
next := focus_find_next(candidates, 20) or { panic('missing next focus') }
assert next.id_focus == 30
fallback := focus_find_next(candidates, 99) or { panic('missing fallback focus') }
assert fallback.id_focus == 10
}
fn test_focus_find_previous_by_id_without_sort() {
s1 := &Shape{
id_focus: 30
}
s2 := &Shape{
id_focus: 10
}
s3 := &Shape{
id_focus: 40
}
candidates := [
FocusCandidate{
id: 30
shape: s1
},
FocusCandidate{
id: 10
shape: s2
},
FocusCandidate{
id: 40
shape: s3
},
]
prev := focus_find_previous(candidates, 35) or { panic('missing previous focus') }
assert prev.id_focus == 30
fallback := focus_find_previous(candidates, 1) or { panic('missing fallback focus') }
assert fallback.id_focus == 40
}