dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 11 / 0 / 11
Functions: 100.0% 1 / 0 / 1
Branches: 90.9% 20 / 0 / 22

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