Skip to content

Commit 8947d43

Browse files
committed
fix #966
1 parent ce76a6d commit 8947d43

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/info/langs/language.tera

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn __stats_loc(language_type: &tokei::LanguageType, stats: &tokei::CodeStats) ->
126126
{%- set line_types = attrs.line_types | default(value=['code']) -%}
127127
tokei::LanguageType::{{ language }} => stats.{{ line_types.0 }}{% for line_type in line_types | slice(start=1) %} + stats.{{ line_type }}{% endfor %},
128128
{% endfor %}
129-
_ => unimplemented!("Language Type {:?}", language_type),
129+
_ => 0, // Tokei doesn't filter children languages according to the input config
130130
}
131131
}
132132

src/info/langs/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,35 @@ mod test {
173173
assert_eq!(loc_by_language[&Language::Jupyter], 21);
174174
}
175175

176+
// https://github.com/o2sh/onefetch/issues/966
177+
#[test]
178+
fn get_loc_by_language_should_not_panic_when_children_language_is_not_supported() {
179+
let mut stylus_code_stats = tokei::CodeStats::new();
180+
stylus_code_stats.code = 10;
181+
stylus_code_stats.blanks = 2;
182+
stylus_code_stats.comments = 4;
183+
184+
let mut stylus_report = tokei::Report::new("/tmp/file.vue".into());
185+
stylus_report.stats = stylus_code_stats;
186+
187+
let mut vue = tokei::Language {
188+
blanks: 50,
189+
comments: 200,
190+
code: 100,
191+
..Default::default()
192+
};
193+
194+
vue.children
195+
.insert(tokei::LanguageType::Stylus, vec![stylus_report]);
196+
197+
let mut languages = tokei::Languages::new();
198+
languages.insert(tokei::LanguageType::Vue, vue);
199+
200+
let loc_by_language = get_loc_by_language(&languages).unwrap();
201+
202+
assert_eq!(loc_by_language[&Language::Vue], 100);
203+
}
204+
176205
#[test]
177206
fn test_get_loc_by_language_sorted() {
178207
let mut map = HashMap::new();

0 commit comments

Comments
 (0)