mirror of
https://github.com/XAMPPRocky/tokei
synced 2024-10-01 05:23:37 +00:00
Add blobs to the totals for jupyter (#868)
This commit is contained in:
parent
cf1c64faa2
commit
452e97b921
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
10
src/stats.rs
10
src/stats.rs
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue