dte test coverage


Directory: ./
File: test/status.c
Date: 2025-02-14 16:55:22
Exec Total Coverage
Lines: 59 59 100.0%
Functions: 1 1 100.0%
Branches: 4 4 100.0%

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