dte test coverage


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