dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 60 / 0 / 60
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 4 / 0 / 4

test/status.c
Line Branch Exec Source
1 #include "test.h"
2 #include "cmdline.h"
3 #include "commands.h"
4 #include "encoding.h"
5 #include "search.h"
6 #include "status.h"
7 #include "util/intern.h"
8 #include "util/utf8.h"
9
10 1 static void test_sf_format(TestContext *ctx)
11 {
12 3 Buffer buffer = {
13 1 .encoding = encoding_from_type(UTF8),
14 1 .options = {.filetype = str_intern("none")},
15 };
16
17 1 Block *block = block_new(1);
18 1 list_init(&buffer.blocks);
19 1 list_insert_before(&block->node, &buffer.blocks);
20
21 1 View view = {
22 .buffer = &buffer,
23 1 .cursor = block_iter(&buffer),
24 };
25
26 1 GlobalOptions opts = {.case_sensitive_search = CSS_FALSE};
27 1 Window window = {.view = &view};
28 1 view.window = &window;
29
30 1 ModeHandler mode = {
31 .name = "normal",
32 .cmds = &normal_commands,
33 };
34
35 1 char buf[64];
36 1 size_t width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%% %n%s%y%s%Y%S%f%s%m%s%r... %E %t%S%N");
37 1 EXPECT_EQ(width, 35);
38 1 EXPECT_STREQ(buf, "% LF 1 0 (No name) ... UTF-8 none");
39
40 1 width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%b%s%n%s%N%s%r%s%o");
41 1 EXPECT_EQ(width, 7);
42 1 EXPECT_STREQ(buf, " LF INS");
43
44 1 buffer.bom = true;
45 1 buffer.crlf_newlines = true;
46 1 buffer.temporary = true;
47 1 buffer.options.overwrite = true;
48 1 width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%b%s%n%s%N%s%r%s%o");
49 1 EXPECT_EQ(width, 21);
50 1 EXPECT_STREQ(buf, "BOM CRLF CRLF TMP OVR");
51
52 1 mode.name = "search";
53 1 mode.cmds = &search_mode_commands;
54 1 width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%M");
55 1 EXPECT_EQ(width, 24);
56 1 EXPECT_STREQ(buf, "[case-sensitive = false]");
57
58 1 opts.case_sensitive_search = CSS_AUTO;
59 1 width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%M");
60 1 EXPECT_EQ(width, 23);
61 1 EXPECT_STREQ(buf, "[case-sensitive = auto]");
62
63 1 opts.case_sensitive_search = CSS_TRUE;
64 1 width = sf_format(&window, &opts, &mode, buf, sizeof buf, "%M%M%M%M%M%M%M");
65 1 EXPECT_TRUE(width >= 46);
66 1 ASSERT_TRUE(width < sizeof(buf));
67 1 ASSERT_NONNULL(memchr(buf, '\0', sizeof(buf)));
68 1 EXPECT_TRUE(str_has_prefix(buf, "[case-sensitive = true][case-sensitive = true]"));
69
70 1 static const char expected[][8] = {
71 ['%'] = "%",
72 ['E'] = "UTF-8",
73 ['N'] = "CRLF",
74 ['X'] = "1",
75 ['Y'] = "0",
76 ['b'] = "BOM",
77 ['f'] = "12\xF0\x9F\x91\xBD", // 👽 (U+1F47D)
78 ['i'] = "normal",
79 ['n'] = "CRLF",
80 ['o'] = "OVR",
81 ['p'] = "All",
82 ['r'] = "TMP",
83 ['t'] = "none",
84 ['x'] = "1",
85 ['y'] = "1",
86 };
87
88 1 mode.name = "normal";
89 1 mode.cmds = &normal_commands;
90 1 buffer.display_filename = (char*)expected['f'];
91 1 EXPECT_EQ(u_str_width(expected['f']), 4);
92
93 1 char fmt[4] = "%_";
94
2/2
✓ Branch 40 → 30 taken 122 times.
✓ Branch 40 → 41 taken 1 time.
123 FOR_EACH_I(i, expected) {
95 122 fmt[1] = (char)i;
96 122 size_t err = statusline_format_find_error(fmt);
97
2/2
✓ Branch 31 → 32 taken 102 times.
✓ Branch 31 → 34 taken 20 times.
122 if (err) {
98 102 EXPECT_UINT_EQ(err, 1);
99 102 continue;
100 }
101 20 width = sf_format(&window, &opts, &mode, buf, sizeof(buf), fmt);
102 20 ASSERT_NONNULL(memchr(buf, '\0', sizeof(buf)));
103 20 IEXPECT_STREQ(buf, expected[i]);
104 20 IEXPECT_EQ(width, u_str_width(expected[i]));
105 }
106
107 1 block_free(block);
108 1 }
109
110 static const TestEntry tests[] = {
111 TEST(test_sf_format),
112 };
113
114 const TestGroup status_tests = TEST_GROUP(tests);
115