// Handle case where file doesn't end with newline
if!line_buffer.is_empty(){
total_lines+=1;
}
letwhitespace_ratio=iftotal_chars>0{
whitespace_countasf64/total_charsasf64
}else{
0.0
};
FileMetrics{
long_lines_count,
total_lines,
whitespace_ratio,
has_license_comment: has_license,
}
}
#[cfg(test)]
modtests{
usesuper::*;
#[test]
fntest_normal_js(){
letcontent=r#"
functionhello(){
// This is a normal comment
console.log("Hello, world!");
}
// Another comment
constx=42;
/* Multi-line
comment*/
"#;
letmetrics=analyze_content(content);
assert!(!metrics.is_likely_minified());
}
#[test]
fntest_minified_file_col_length(){
letcontent=
"const LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`";
letmetrics=analyze_content(content);
assert!(metrics.is_likely_minified());
}
#[test]
fntest_minified_js(){
letcontent="function hello(){console.log(\"Hello, world!\")}const x=42;function veryLongFunction(){return\"This is a very long line that exceeds 250 characters and contains lots of code and stuff and more code and even more stuff until we definitely exceed the limit we set for considering a line to be very long in our minification detection algorithm\"}";