v2 / vlib / v / tests / fns / closure_struct_init_cov_regression_test.v
38 lines · 34 sloc · 838 bytes · 51ae459f2d0157a77f15503dce739d3de6c9ff7e
Raw
1// vtest vflags: -cov .vtmp_cov_issue_24842
2module main
3
4import term.ui as tui
5
6enum ThemeSlot {
7 primary
8}
9
10struct CoverageClosureCtx {
11 active_fg_color tui.Color
12 on_draw_cb fn (int, int, string, tui.Color, ?tui.Color)
13 on_draw_rect_cb fn (int, int, int, int)
14}
15
16fn test_cov_struct_init_with_closures_and_index_or() {
17 palette := map[ThemeSlot]tui.Color{}
18 key := ThemeSlot.primary
19 mut drawn := []int{}
20 mut drawn_ref := &drawn
21 _ = CoverageClosureCtx{
22 active_fg_color: palette[key] or {
23 tui.Color{
24 r: 1
25 g: 2
26 b: 3
27 }
28 }
29 on_draw_cb: fn [mut drawn_ref] (x int, y int, text string, fg tui.Color, bg ?tui.Color) {
30 drawn_ref << x + y + text.len + fg.r
31 _ = bg
32 }
33 on_draw_rect_cb: fn [mut drawn_ref] (x int, y int, width int, height int) {
34 drawn_ref << x + y + width + height
35 }
36 }
37 assert true
38}
39