dte test coverage


Directory: ./
File: src/case.c
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 23 38 60.5%
Functions: 1 1 100.0%
Branches: 9 22 40.9%

Line Branch Exec Source
1 #include <stdbool.h>
2 #include <stdlib.h>
3 #include "case.h"
4 #include "block-iter.h"
5 #include "change.h"
6 #include "selection.h"
7 #include "util/debug.h"
8 #include "util/string.h"
9 #include "util/unicode.h"
10 #include "util/utf8.h"
11
12 2 void change_case(View *view, char mode)
13 {
14 2 bool was_selecting = false;
15 2 bool move = true;
16 2 size_t text_len;
17
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→6) taken 2 times.
2 if (view->selection) {
18 SelectionInfo info = init_selection(view);
19 view->cursor = info.si;
20 text_len = info.eo - info.so;
21 unselect(view);
22 was_selecting = true;
23 move = !info.swapped;
24 } else {
25 2 CodePoint u;
26
1/2
✗ Branch 0 (7→8) not taken.
✓ Branch 1 (7→9) taken 2 times.
2 if (!block_iter_get_char(&view->cursor, &u)) {
27 return;
28 }
29 2 text_len = u_char_size(u);
30 }
31
32 2 String dst = string_new(text_len);
33 2 char *src = block_iter_get_bytes(&view->cursor, text_len);
34 2 size_t i = 0;
35
1/4
✗ Branch 0 (12→15) not taken.
✗ Branch 1 (12→18) not taken.
✓ Branch 2 (12→24) taken 2 times.
✗ Branch 3 (12→25) not taken.
2 switch (mode) {
36 case 'l':
37 while (i < text_len) {
38 CodePoint u = u_to_lower(u_get_char(src, text_len, &i));
39 string_append_codepoint(&dst, u);
40 }
41 break;
42 case 'u':
43 while (i < text_len) {
44 CodePoint u = u_to_upper(u_get_char(src, text_len, &i));
45 string_append_codepoint(&dst, u);
46 }
47 break;
48 case 't':
49
2/2
✓ Branch 0 (24→19) taken 2 times.
✓ Branch 1 (24→26) taken 2 times.
4 while (i < text_len) {
50 2 CodePoint u = u_get_char(src, text_len, &i);
51
1/2
✗ Branch 0 (20→21) not taken.
✓ Branch 1 (20→22) taken 2 times.
2 u = u_is_upper(u) ? u_to_lower(u) : u_to_upper(u);
52 2 string_append_codepoint(&dst, u);
53 }
54 break;
55 default:
56 BUG("unhandled case mode");
57 }
58
59 2 buffer_replace_bytes(view, text_len, dst.buffer, dst.len);
60 2 free(src);
61
62
2/4
✓ Branch 0 (27→28) taken 2 times.
✗ Branch 1 (27→33) not taken.
✓ Branch 2 (28→29) taken 2 times.
✗ Branch 3 (28→33) not taken.
2 if (move && dst.len > 0) {
63 2 size_t skip = dst.len;
64
1/2
✗ Branch 0 (29→30) not taken.
✓ Branch 1 (29→31) taken 2 times.
2 if (was_selecting) {
65 // Move cursor back to where it was
66 u_prev_char(dst.buffer, &skip);
67 }
68 2 block_iter_skip_bytes(&view->cursor, skip);
69 }
70
71 2 string_free(&dst);
72 }
73