dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 17 / 0 / 17
Functions: 100.0% 3 / 0 / 3
Branches: 100.0% 7 / 4 / 11

src/selection.h
Line Branch Exec Source
1 #ifndef SELECTION_H
2 #define SELECTION_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include "block-iter.h"
7 #include "buffer.h"
8 #include "command/args.h"
9 #include "command/run.h"
10 #include "util/debug.h"
11 #include "util/macros.h"
12 #include "util/string-view.h"
13 #include "view.h"
14
15 typedef struct {
16 BlockIter si;
17 size_t so;
18 size_t eo;
19 bool swapped;
20 } SelectionInfo;
21
22 void view_do_set_selection_type(View *view, SelectionType sel) NOINLINE;
23
24 136 static inline void view_set_selection_type(View *view, SelectionType sel)
25 {
26
2/2
✓ Branch 2 → 3 taken 120 times.
✓ Branch 2 → 6 taken 16 times.
136 if (likely(sel == view->selection)) {
27 // If `sel` is SELECT_NONE here, it's always equal to select_mode
28 120 BUG_ON(!sel && view->select_mode);
29 return;
30 }
31
32 16 view_do_set_selection_type(view, sel);
33 }
34
35 133 static inline SelectionType handle_selection_flags(View *view, const CommandArgs *a)
36 {
37 133 SelectionType sel = SELECT_NONE;
38
3/3
✓ Branch 3 → 4 taken 10 times.
✓ Branch 3 → 5 taken 15 times.
✓ Branch 3 → 6 taken 108 times.
133 switch (cmdargs_pick_winning_flag(a, "cl")) {
39 10 case 'c': sel = SELECT_CHARS; break;
40 15 case 'l': sel = SELECT_LINES; break;
41 }
42
43 133 view_set_selection_type(view, MAX(sel, view->select_mode));
44 133 return sel;
45 }
46
47 149 static inline bool unselect(View *view)
48 {
49
2/2
✓ Branch 2 → 3 taken 13 times.
✓ Branch 2 → 4 taken 136 times.
149 if (view->selection) {
50 13 view->selection = SELECT_NONE;
51 13 view->select_mode = SELECT_NONE;
52 13 mark_all_lines_changed(view->buffer);
53 }
54 149 return true; // To allow tail-calling from command handlers
55 }
56
57 SelectionInfo init_selection(const View *view) NONNULL_ARGS WARN_UNUSED_RESULT;
58 size_t prepare_selection(View *view) NONNULL_ARGS WARN_UNUSED_RESULT;
59 size_t get_nr_selected_lines(const SelectionInfo *info) NONNULL_ARGS WARN_UNUSED_RESULT;
60 size_t get_nr_selected_chars(const SelectionInfo *info) NONNULL_ARGS WARN_UNUSED_RESULT;
61
62 void select_block(View *view) NONNULL_ARGS;
63 bool line_has_opening_brace(StringView line) WARN_UNUSED_RESULT;
64 bool line_has_closing_brace(StringView line) WARN_UNUSED_RESULT;
65
66 #endif
67