dte test coverage


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