This commit is contained in:
Jordan Pittman 2022-11-25 11:51:32 -05:00 • committed by Robin Malfait
parent 52edffba86
commit 30b7d3fcc2
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE
3 changed files with 38 additions and 0 deletions

View file

@ -11,6 +11,7 @@ rayon = "1.5.3"
fxhash = "0.2.1"
crossbeam = "0.8.2"
tracing = { version = "0.1.37", features = ["max_level_trace", "release_max_level_warn"] }
tracing-subscriber = "0.3.16"
[dev-dependencies]
criterion = { version = "0.3", features = ['html_reports'] }

View file

@ -1,5 +1,6 @@
use crate::parser::Extractor;
use rayon::prelude::*;
use tracing::event;
use std::path::PathBuf;
pub mod candidate;
@ -18,10 +19,19 @@ pub struct ChangedContent {
}
pub fn parse_candidate_strings_from_files(changed_content: Vec<ChangedContent>) -> Vec<String> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE)
.compact()
.init();
parse_all_blobs(read_all_files(changed_content))
}
#[tracing::instrument(skip(changed_content))]
fn read_all_files(changed_content: Vec<ChangedContent>) -> Vec<Vec<u8>> {
event!(tracing::Level::INFO, "Reading {:?} file(s)", changed_content.len());
changed_content
.into_par_iter()
.map(|c| match (c.file, c.content) {
@ -52,3 +62,22 @@ fn parse_all_blobs(blobs: Vec<Vec<u8>>) -> Vec<String> {
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_candidate_strings_from_files() {
let changed_content = vec![ChangedContent {
file: Some(PathBuf::from("benches/fixtures/template-000.html")),
content: None,
extension: "html".to_string(),
}];
let candidates = parse_candidate_strings_from_files(changed_content);
assert_eq!(candidates.len(), 808);
assert_eq!(candidates[0], "md:h-72");
}
}

View file

@ -438,6 +438,14 @@ impl<'a> Iterator for Extractor<'a> {
mod test {
use super::*;
fn please_trace() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE)
.compact()
.init();
}
fn run(input: &str, loose: bool) -> Vec<&str> {
Extractor::new(
input.as_bytes(),