dte test coverage


Directory: ./
File: src/filetype/basenames.c
Date: 2025-05-08 15:05:54
Exec Total Coverage
Lines: 14 14 100.0%
Functions: 1 1 100.0%
Branches: 20 22 90.9%

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 {"bash_aliases", SH, true},
43 {"bash_functions", SH, true},
44 {"bash_logout", SH, true},
45 {"bash_profile", SH, true},
46 {"bashrc", SH, true},
47 {"bazelrc", CONFIG, true},
48 {"build.gradle", GRADLE, false},
49 {"buildozer.spec", INI, false},
50 {"bun.lock", JSONC, false}, // https://bun.sh/blog/bun-lock-text-lockfile#tooling-compatibility
51 {"clang-format", YAML, true},
52 {"clang-tidy", YAML, true},
53 {"colordiffrc", CONFIG, true},
54 {"composer.lock", JSON, false},
55 {"config.ld", LUA, false},
56 {"configure.ac", M4, false},
57 {"coveragerc", INI, true},
58 {"csh.login", CSH, true},
59 {"csh.logout", CSH, true},
60 {"cshdirs", CSH, true},
61 {"cshrc", CSH, true},
62 {"curlrc", CONFIG, true},
63 {"deno.lock", JSON, false},
64 {"dir_colors", CONFIG, true},
65 {"dircolors", CONFIG, true},
66 {"doas.conf", CONFIG, false},
67 {"drirc", XML, true},
68 {"dterc", DTE, true},
69 {"editorconfig", INI, true},
70 {"emacs", LISP, true},
71 {"flake.lock", JSON, false},
72 {"flake8", INI, true},
73 {"fstab", CONFIG, false},
74 {"gdbinit", CONFIG, true},
75 {"gemrc", YAML, true},
76 {"git-rebase-todo", GITREBASE, false},
77 {"gitattributes", CONFIG, true},
78 {"gitconfig", INI, true},
79 {"gitignore", GITIGNORE, true},
80 {"gitmodules", INI, true},
81 {"gnus", LISP, true},
82 {"go.mod", GOMODULE, false},
83 {"hosts", CONFIG, false},
84 {"htmlhintrc", JSON, true},
85 {"indent.pro", INDENT, true},
86 {"inputrc", CONFIG, true},
87 {"ip6tables.rules", CONFIG, false},
88 {"iptables.rules", CONFIG, false},
89 {"jshintrc", JSON, true},
90 {"krb5.conf", INI, false},
91 {"lcovrc", CONFIG, true},
92 {"lesskey", CONFIG, true},
93 {"luacheckrc", LUA, true},
94 {"luacov", LUA, true},
95 {"makefile", MAKE, false},
96 {"mcmod.info", JSON, false},
97 {"menu.lst", CONFIG, false},
98 {"meson.build", MESON, false},
99 {"mimeapps.list", INI, false},
100 {"mkinitcpio.conf", SH, false},
101 {"muttrc", CONFIG, true},
102 {"nanorc", CONFIG, true},
103 {"nftables.conf", NFTABLES, false},
104 {"nginx.conf", NGINX, false},
105 {"pacman.conf", INI, false},
106 {"pdm.lock", TOML, false},
107 {"poetry.lock", TOML, false},
108 {"profile", SH, true},
109 {"pylintrc", INI, true},
110 {"robots.txt", ROBOTSTXT, false},
111 {"rockspec.in", LUA, false},
112 {"shellcheckrc", CONFIG, true},
113 {"shrc", SH, true},
114 {"sudoers", CONFIG, false},
115 {"sxhkdrc", CONFIG, true},
116 {"tags", CTAGS, false},
117 {"tcshrc", CSH, true},
118 {"terminalrc", INI, false},
119 {"terminfo.src", TERMINFO, false},
120 {"texmf.cnf", TEXMFCNF, false},
121 {"tigrc", CONFIG, true},
122 {"tmux.conf", TMUX, true},
123 {"user-dirs.conf", CONFIG, false},
124 {"user-dirs.dirs", CONFIG, false},
125 {"vconsole.conf", CONFIG, false},
126 {"watchmanconfig", JSON, true},
127 {"xinitrc", SH, true},
128 {"xprofile", SH, true},
129 {"xserverrc", SH, true},
130 {"yum.conf", INI, false},
131 {"zlogin", SH, true},
132 {"zlogout", SH, true},
133 {"zprofile", SH, true},
134 {"zshenv", SH, true},
135 {"zshrc", SH, true},
136 };
137
138 215 static FileTypeEnum filetype_from_basename(StringView name)
139 {
140 215 size_t dotprefix = 0;
141
2/2
✓ Branch 0 (3→4) taken 186 times.
✓ Branch 1 (3→7) taken 29 times.
215 if (strview_has_prefix(&name, ".")) {
142 dotprefix = 1;
143
2/2
✓ Branch 0 (5→6) taken 6 times.
✓ Branch 1 (5→7) taken 180 times.
186 } else if (strview_has_prefix(&name, "dot_")) {
144 6 dotprefix = 4;
145 }
146
147 215 strview_remove_prefix(&name, dotprefix);
148
2/2
✓ Branch 0 (8→9) taken 140 times.
✓ Branch 1 (8→25) taken 75 times.
215 if (name.length < 4) {
149 return NONE;
150 }
151
152
2/2
✓ Branch 0 (9→10) taken 6 times.
✓ Branch 1 (9→20) taken 134 times.
140 if (name.length >= ARRAYLEN(basenames[0].name)) {
153
2/2
✓ Branch 0 (11→12) taken 1 times.
✓ Branch 1 (11→15) taken 5 times.
6 if (strview_equal_cstring(&name, "meson_options.txt")) {
154
1/2
✓ Branch 0 (12→13) taken 1 times.
✗ Branch 1 (12→14) not taken.
1 return dotprefix ? NONE : MESON;
155
2/2
✓ Branch 0 (16→17) taken 1 times.
✓ Branch 1 (16→25) taken 4 times.
5 } else if (strview_equal_cstring(&name, "git-blame-ignore-revs")) {
156
1/2
✗ Branch 0 (17→18) not taken.
✓ Branch 1 (17→19) taken 1 times.
1 return dotprefix ? CONFIG : NONE;
157 }
158 return NONE;
159 }
160
161 134 const struct FileBasenameMap *e = BSEARCH(&name, basenames, ft_compare);
162
6/6
✓ Branch 0 (21→22) taken 38 times.
✓ Branch 1 (21→25) taken 96 times.
✓ Branch 2 (22→23) taken 20 times.
✓ Branch 3 (22→24) taken 18 times.
✓ Branch 4 (23→24) taken 19 times.
✓ Branch 5 (23→25) taken 1 times.
134 return (e && (dotprefix == 0 || e->dotfile)) ? e->filetype : NONE;
163 }
164