dte test coverage


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

src/filetype/interpreters.c
Line Branch Exec Source
1 #include "filetype/types.h"
2 #include "util/bsearch.h"
3
4 static const struct FileInterpreterMap {
5 const char key[8];
6 const FileTypeEnum filetype;
7 } interpreters[] = {
8 {"ash", SH},
9 {"awk", AWK},
10 {"bash", SH},
11 {"bats", SH}, // https://github.com/bats-core/bats-core
12 {"bigloo", SCHEME},
13 {"bun", TYPESCRIPT},
14 {"ccl", LISP},
15 {"chicken", SCHEME},
16 {"clisp", LISP},
17 {"coffee", COFFEESCRIPT},
18 {"crystal", RUBY},
19 {"csh", CSH},
20 {"dart", DART},
21 {"dash", SH},
22 {"deno", TYPESCRIPT},
23 {"ecl", LISP},
24 {"elixir", ELIXIR},
25 {"escript", ERLANG},
26 {"fish", FISH},
27 {"gawk", AWK},
28 {"gjs", JAVASCRIPT},
29 {"gmake", MAKE},
30 {"gnuplot", GNUPLOT},
31 {"gojq", JQ}, // https://github.com/itchyny/gojq
32 {"groovy", GROOVY},
33 {"gsed", SED},
34 {"guile", SCHEME},
35 {"jaq", JQ}, // https://github.com/01mf02/jaq
36 {"jq", JQ},
37 {"jruby", RUBY},
38 {"julia", JULIA},
39 {"ksh", SH},
40 {"lisp", LISP},
41 {"lua", LUA},
42 {"luajit", LUA},
43 {"macruby", RUBY},
44 {"make", MAKE},
45 {"mawk", AWK},
46 {"mksh", SH},
47 {"moon", MOONSCRIPT},
48 {"nawk", AWK},
49 {"nft", NFTABLES},
50 {"node", JAVASCRIPT},
51 {"nodejs", JAVASCRIPT},
52 {"ocaml", OCAML},
53 {"pdksh", SH},
54 {"perl", PERL},
55 {"php", PHP},
56 {"pwsh", POWERSHELL},
57 {"pypy", PYTHON},
58 {"python", PYTHON},
59 {"qjs", JAVASCRIPT},
60 {"r6rs", SCHEME},
61 {"racket", SCHEME},
62 {"rake", RUBY},
63 {"rbx", RUBY},
64 {"ruby", RUBY},
65 {"runghc", HASKELL},
66 {"sbcl", LISP},
67 {"scala", SCALA},
68 {"scheme", SCHEME},
69 {"sed", SED},
70 {"sh", SH},
71 {"tcc", C},
72 {"tclsh", TCL},
73 {"tcsh", CSH},
74 {"ts-node", TYPESCRIPT},
75 {"wish", TCL},
76 {"zsh", SH},
77 };
78
79 24 UNITTEST {
80 24 CHECK_BSEARCH_ARRAY(interpreters, key);
81 24 }
82
83 279 FileTypeEnum filetype_from_interpreter(StringView name)
84 {
85
2/2
✓ Branch 2 → 3 taken 67 times.
✓ Branch 2 → 14 taken 212 times.
279 if (name.length < 2) {
86 return NONE;
87 }
88
89
2/2
✓ Branch 3 → 4 taken 5 times.
✓ Branch 3 → 11 taken 62 times.
67 if (name.length >= ARRAYLEN(interpreters[0].key)) {
90
2/2
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 14 taken 1 time.
5 if (strview_equal_cstring(name, "openrc-run")) {
91 return SH;
92
2/2
✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 14 taken 1 time.
4 } else if (strview_equal_cstring(name, "runhaskell")) {
93 return HASKELL;
94
2/2
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 14 taken 1 time.
3 } else if (strview_equal_cstring(name, "rust-script")) {
95 return RUST;
96 }
97 2 return NONE;
98 }
99
100 62 const struct FileInterpreterMap *e = BSEARCH(&name, interpreters, ft_compare);
101
2/2
✓ Branch 12 → 13 taken 59 times.
✓ Branch 12 → 14 taken 3 times.
62 return e ? e->filetype : NONE;
102 }
103