Add blobs to the totals for jupyter (#868)

This commit is contained in:
LovecraftianHorror 2021-12-19 16:05:19 -06:00 committed by GitHub
parent cf1c64faa2
commit 452e97b921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View file

@ -260,7 +260,8 @@ impl LanguageType {
.collect::<Vec<_>>();
for (language, stats) in iter {
*jupyter_stats.blobs.entry(language).or_default() += stats;
*jupyter_stats.blobs.entry(language).or_default() += &stats;
jupyter_stats += &stats;
}
Some(jupyter_stats)
@ -271,8 +272,29 @@ impl LanguageType {
mod tests {
use super::*;
use std::{fs, path::Path};
#[test]
fn rust_allows_nested() {
assert!(LanguageType::Rust.allows_nested());
}
#[test]
fn jupyter_notebook_has_correct_totals() {
let sample_notebook =
fs::read_to_string(Path::new("tests").join("data").join("jupyter.ipynb")).unwrap();
let CodeStats {
blanks,
code,
comments,
..
} = LanguageType::Jupyter
.parse_jupyter(sample_notebook.as_bytes(), &Config::default())
.unwrap();
assert_eq!(blanks, 115);
assert_eq!(code, 528);
assert_eq!(comments, 333);
}
}

View file

@ -46,12 +46,18 @@ impl CodeStats {
impl ops::AddAssign for CodeStats {
fn add_assign(&mut self, rhs: Self) {
self.add_assign(&rhs);
}
}
impl ops::AddAssign<&'_ CodeStats> for CodeStats {
fn add_assign(&mut self, rhs: &'_ CodeStats) {
self.blanks += rhs.blanks;
self.code += rhs.code;
self.comments += rhs.comments;
for (language, stats) in rhs.blobs {
*self.blobs.entry(language).or_default() += stats;
for (language, stats) in &rhs.blobs {
*self.blobs.entry(*language).or_default() += stats;
}
}
}