dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 13 / 0 / 13
Functions: 100.0% 2 / 0 / 2
Branches: 88.9% 16 / 0 / 18

src/filetype/basenames.c
Line Branch Exec Source
1 #include <stdint.h>
2 #include "filetype/types.h"
3 #include "util/bsearch.h"
4 #include "util/debug.h"
5
6 static const struct FileBasenameMap {
7 const char name[16];
8 uint8_t filetype; // FileTypeEnum
9 bool dotfile; // If true, name is matched with or without a leading dot
10 } basenames[] = {
11 {"APKBUILD", SH, false},
12 {"BSDmakefile", MAKE, false},
13 {"BUILD.bazel", PYTHON, false},
14 {"Brewfile", RUBY, true},
15 {"CMakeLists.txt", CMAKE, false},
16 {"COMMIT_EDITMSG", GITCOMMIT, false},
17 {"Capfile", RUBY, false},
18 {"Cargo.lock", TOML, false},
19 {"DIR_COLORS", CONFIG, false},
20 {"Dangerfile", RUBY, false},
21 {"Dockerfile", DOCKER, false},
22 {"Doxyfile", CONFIG, false},
23 {"GNUmakefile", MAKE, false},
24 {"Gemfile", RUBY, false},
25 {"Gemfile.lock", RUBY, false},
26 {"Guardfile", RUBY, true},
27 {"Kbuild", MAKE, false},
28 {"Kconfig", CONFIG, false},
29 {"Kconfig.debug", CONFIG, false},
30 {"MERGE_MSG", GITCOMMIT, false},
31 {"Makefile", MAKE, false},
32 {"Makefile.am", MAKE, false},
33 {"Makefile.in", MAKE, false},
34 {"NOTES_EDITMSG", GITNOTE, false},
35 {"PKGBUILD", SH, false},
36 {"Pipfile", TOML, false},
37 {"Pipfile.lock", JSON, false},
38 {"Project.ede", LISP, false},
39 {"Puppetfile", RUBY, false},
40 {"Rakefile", RUBY, false},
41 {"Steepfile", RUBY, false},
42 {"Thorfile", RUBY, false},
43 {"Vagrantfile", RUBY, false},
44 {"XCompose", CONFIG, true},
45 {"Xresources", XRESOURCES, true},
46 {"ackrc", CONFIG, true},
47 {"alsoftrc", INI, true}, // https://github.com/kcat/openal-soft/blob/master/alsoftrc.sample
48 {"bash_aliases", SH, true},
49 {"bash_functions", SH, true},
50 {"bash_logout", SH, true},
51 {"bash_profile", SH, true},
52 {"bashrc", SH, true},
53 {"bazelrc", CONFIG, true},
54 {"btop.conf", CONFIG, true},
55 {"build.gradle", GRADLE, false},
56 {"buildozer.spec", INI, false},
57 {"bun.lock", JSONC, false}, // https://bun.sh/blog/bun-lock-text-lockfile#tooling-compatibility
58 {"clang-format", YAML, true},
59 {"clang-tidy", YAML, true},
60 {"colordiffrc", CONFIG, true},
61 {"composer.lock", JSON, false},
62 {"config.ld", LUA, false},
63 {"configure.ac", M4, false},
64 {"coveragerc", INI, true},
65 {"csh.login", CSH, true},
66 {"csh.logout", CSH, true},
67 {"cshdirs", CSH, true},
68 {"cshrc", CSH, true},
69 {"curlrc", CONFIG, true},
70 {"deno.lock", JSON, false},
71 {"dir_colors", CONFIG, true},
72 {"dircolors", CONFIG, true},
73 {"doas.conf", CONFIG, false},
74 {"drirc", XML, true},
75 {"dterc", DTE, true},
76 {"editorconfig", INI, true},
77 {"emacs", LISP, true},
78 {"flake.lock", JSON, false},
79 {"flake8", INI, true},
80 {"fstab", CONFIG, false},
81 {"gdbinit", CONFIG, true},
82 {"gemrc", YAML, true},
83 {"git-rebase-todo", GITREBASE, false},
84 {"gitattributes", CONFIG, true},
85 {"gitconfig", INI, true},
86 {"gitignore", GITIGNORE, true},
87 {"gitmodules", INI, true},
88 {"gnus", LISP, true},
89 {"go.mod", GOMODULE, false},
90 {"hosts", CONFIG, false},
91 {"htmlhintrc", JSON, true},
92 {"indent.pro", INDENT, true},
93 {"index.theme", INI, false}, // https://specifications.freedesktop.org/icon-theme/latest/#directory_layout:~:text=file%20called-,index.theme
94 {"inputrc", CONFIG, true},
95 {"ip6tables.rules", CONFIG, false},
96 {"iptables.rules", CONFIG, false},
97 {"jshintrc", JSON, true},
98 {"kitty.conf", CONFIG_NTC, false},
99 {"krb5.conf", INI, false},
100 {"lcovrc", CONFIG, true},
101 {"lesskey", CONFIG, true},
102 {"luacheckrc", LUA, true},
103 {"luacov", LUA, true},
104 {"makefile", MAKE, false},
105 {"mcmod.info", JSON, false},
106 {"menu.lst", CONFIG, false},
107 {"meson.build", MESON, false},
108 {"mimeapps.list", INI, false},
109 {"mkinitcpio.conf", SH, false},
110 {"muttrc", CONFIG, true},
111 {"nanorc", CONFIG, true},
112 {"nftables.conf", NFTABLES, false},
113 {"nginx.conf", NGINX, false},
114 {"pacman.conf", INI, false},
115 {"pdm.lock", TOML, false},
116 {"poetry.lock", TOML, false},
117 {"profile", SH, true},
118 {"pylintrc", INI, true},
119 {"robots.txt", ROBOTSTXT, false},
120 {"rockspec.in", LUA, false},
121 {"shellcheckrc", CONFIG, true},
122 {"shrc", SH, true},
123 {"sudoers", CONFIG, false},
124 {"sxhkdrc", CONFIG, true},
125 {"tags", CTAGS, false},
126 {"tcshrc", CSH, true},
127 {"terminalrc", INI, false},
128 {"terminfo.src", TERMINFO, false},
129 {"texmf.cnf", TEXMFCNF, false},
130 {"tigrc", CONFIG, true},
131 {"tmux.conf", TMUX, true},
132 {"user-dirs.conf", CONFIG, false},
133 {"user-dirs.dirs", CONFIG, false},
134 {"vconsole.conf", CONFIG, false},
135 {"watchmanconfig", JSON, true},
136 {"xinitrc", SH, true},
137 {"xprofile", SH, true},
138 {"xserverrc", SH, true},
139 {"yum.conf", INI, false},
140 {"zlogin", SH, true},
141 {"zlogout", SH, true},
142 {"zprofile", SH, true},
143 {"zshenv", SH, true},
144 {"zshrc", SH, true},
145 };
146
147 24 UNITTEST {
148 24 CHECK_BSEARCH_ARRAY(basenames, name);
149 24 }
150
151 217 FileTypeEnum filetype_from_basename(StringView name)
152 {
153 217 bool dot = strview_remove_either_matching_prefix(&name, ".", "dot_");
154
2/2
✓ Branch 3 → 4 taken 142 times.
✓ Branch 3 → 18 taken 75 times.
217 if (name.length < 4) {
155 return NONE;
156 }
157
158
2/2
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 13 taken 136 times.
142 if (name.length >= ARRAYLEN(basenames[0].name)) {
159
2/2
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 9 taken 5 times.
6 if (strview_equal_cstring(name, "meson_options.txt")) {
160
1/2
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 18 not taken.
1 return dot ? NONE : MESON;
161
2/2
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 18 taken 4 times.
5 } else if (strview_equal_cstring(name, "git-blame-ignore-revs")) {
162
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 18 taken 1 time.
1 return dot ? CONFIG : NONE;
163 }
164 return NONE;
165 }
166
167 136 const struct FileBasenameMap *e = BSEARCH(&name, basenames, ft_compare);
168
6/6
✓ Branch 14 → 15 taken 38 times.
✓ Branch 14 → 18 taken 98 times.
✓ Branch 15 → 16 taken 20 times.
✓ Branch 15 → 17 taken 18 times.
✓ Branch 16 → 17 taken 19 times.
✓ Branch 16 → 18 taken 1 time.
136 return (e && (!dot || e->dotfile)) ? e->filetype : NONE;
169 }
170