dte test coverage


Directory: ./
File: src/delete.c
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 50 50 100.0%
Functions: 3 3 100.0%
Branches: 20 26 76.9%

Line Branch Exec Source
1 #include <stdlib.h>
2 #include <string.h>
3 #include "delete.h"
4 #include "buffer.h"
5 #include "change.h"
6 #include "indent.h"
7 #include "options.h"
8 #include "selection.h"
9 #include "util/debug.h"
10 #include "util/string.h"
11 #include "util/string-view.h"
12 #include "util/utf8.h"
13
14 9 void delete_ch(View *view)
15 {
16 9 size_t size = 0;
17
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→5) taken 7 times.
9 if (view->selection) {
18 2 size = prepare_selection(view);
19 2 unselect(view);
20 } else {
21 7 const LocalOptions *options = &view->buffer->options;
22 7 begin_change(CHANGE_MERGE_DELETE);
23
2/2
✓ Branch 0 (6→7) taken 4 times.
✓ Branch 1 (6→9) taken 3 times.
7 if (options->emulate_tab) {
24 4 size = get_indent_level_bytes_right(options, &view->cursor);
25 }
26
1/2
✓ Branch 0 (8→9) taken 4 times.
✗ Branch 1 (8→11) not taken.
4 if (size == 0) {
27 7 BlockIter bi = view->cursor;
28 7 size = block_iter_next_column(&bi);
29 }
30 }
31 9 buffer_delete_bytes(view, size);
32 9 }
33
34 6 void erase(View *view)
35 {
36 6 size_t size = 0;
37
2/2
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→5) taken 5 times.
6 if (view->selection) {
38 1 size = prepare_selection(view);
39 1 unselect(view);
40 } else {
41 5 const LocalOptions *options = &view->buffer->options;
42 5 begin_change(CHANGE_MERGE_ERASE);
43
2/2
✓ Branch 0 (6→7) taken 1 times.
✓ Branch 1 (6→10) taken 4 times.
5 if (options->emulate_tab) {
44 1 size = get_indent_level_bytes_left(options, &view->cursor);
45 1 block_iter_back_bytes(&view->cursor, size);
46 }
47
1/2
✓ Branch 0 (9→10) taken 1 times.
✗ Branch 1 (9→12) not taken.
1 if (size == 0) {
48 5 CodePoint u;
49 5 size = block_iter_prev_char(&view->cursor, &u);
50 }
51 }
52 6 buffer_erase_bytes(view, size);
53 6 }
54
55 4 void clear_lines(View *view, bool auto_indent)
56 {
57 4 char *indent = NULL;
58
1/2
✓ Branch 0 (2→3) taken 4 times.
✗ Branch 1 (2→11) not taken.
4 if (auto_indent) {
59 4 BlockIter bi = view->cursor;
60
3/4
✓ Branch 0 (4→5) taken 2 times.
✓ Branch 1 (4→10) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
✗ Branch 3 (6→10) not taken.
4 if (block_iter_prev_line(&bi) && block_iter_find_non_empty_line_bwd(&bi)) {
61 2 StringView line = block_iter_get_line(&bi);
62 2 indent = get_indent_for_next_line(&view->buffer->options, &line);
63 }
64 }
65
66 4 size_t del_count = 0;
67
2/2
✓ Branch 0 (11→12) taken 1 times.
✓ Branch 1 (11→16) taken 3 times.
4 if (view->selection) {
68 1 view->selection = SELECT_LINES;
69 1 del_count = prepare_selection(view);
70 1 unselect(view);
71 // Don't delete last newline
72
1/2
✓ Branch 0 (14→15) taken 1 times.
✗ Branch 1 (14→18) not taken.
1 if (del_count) {
73 1 del_count--;
74 }
75 } else {
76 3 block_iter_eol(&view->cursor);
77 3 del_count = block_iter_bol(&view->cursor);
78 }
79
80
1/2
✓ Branch 0 (18→19) taken 4 times.
✗ Branch 1 (18→23) not taken.
4 if (!indent && !del_count) {
81 return;
82 }
83
84
2/2
✓ Branch 0 (19→20) taken 2 times.
✓ Branch 1 (19→21) taken 2 times.
4 size_t ins_count = indent ? strlen(indent) : 0;
85 4 buffer_replace_bytes(view, del_count, indent, ins_count);
86 4 free(indent);
87 4 block_iter_skip_bytes(&view->cursor, ins_count);
88 }
89