Skip to content

Commit

Permalink
fix template and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Adinata Wijaya committed Jul 28, 2023
1 parent 46cdfd7 commit 7a0c164
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn compare_files<P: AsRef<Path>>(
);

error!("{}" , &error);
difference.push_detail(DiffDetail::Text {score: distance, line: l});
difference.push_detail(DiffDetail::Text {actual: a, nominal: n, score: distance, line: l});
difference.error();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn compare_files<P: AsRef<Path>>(
);

error!("{}" , &error);
difference.push_detail(DiffDetail::Text {score: distance, line: l});
difference.push_detail(DiffDetail::Text {actual:a.to_owned(), nominal:n.to_owned(), score: distance, line: l});
difference.error();
}
});
Expand Down
75 changes: 50 additions & 25 deletions src/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,24 @@ impl Difference {
#[allow(clippy::upper_case_acronyms)]
pub enum DiffDetail {
CSV(DiffType),
Image { score: f64, diff_image: String },
Text { line: usize, score: f64 },
Hash { actual: String, nominal: String },
External { stdout: String, stderr: String },
Image {
score: f64,
diff_image: String,
},
Text {
actual: String,
nominal: String,
line: usize,
score: f64,
},
Hash {
actual: String,
nominal: String,
},
External {
stdout: String,
stderr: String,
},
Properties(MetaDataPropertyDiff),
Error(String),
}
Expand Down Expand Up @@ -369,7 +383,7 @@ pub fn write_image_detail(
fs::copy(diff_image, &img_target)
.map_err(|e| FatIOError::from_std_io_err(e, img_target.to_path_buf()))?;

ctx.insert("error", score); //TODO: rename this correctly
ctx.insert("error", &format!("Score {score}"));
ctx.insert("diff_image", diff_image);
ctx.insert("actual_image", &actual_image);
ctx.insert("nominal_image", &nominal_image);
Expand All @@ -385,7 +399,7 @@ pub fn write_image_detail(
pub fn write_pdf_detail(
nominal: impl AsRef<Path>,
actual: impl AsRef<Path>,
diffs: &[(&usize, &f64)],
diffs: &[(&usize, String)],
report_dir: impl AsRef<Path>,
) -> Result<Option<DetailPath>, Error> {
let detail_path = create_detail_folder(report_dir.as_ref())?;
Expand Down Expand Up @@ -424,11 +438,8 @@ pub fn write_pdf_detail(
diffs: vec![],
};

if let Some(diff) = diffs.iter().find(|(i, t)| **i == l) {
result.diffs.push(format!(
"Missmatch in line {}, threshold: {}",
diff.0, diff.1
));
if let Some(diff) = diffs.iter().find(|(i, _msg)| **i == l) {
result.diffs.push(diff.1.clone());
};

result
Expand Down Expand Up @@ -616,9 +627,15 @@ pub(crate) fn create_html(
.detail
.iter()
.filter_map(|r| match r {
DiffDetail::Text { line, score } => {
Some(format!("{} {}", line, score)) //TODO: want the text difference
}
DiffDetail::Text {
line,
score,
actual,
nominal,
} => Some(format!(
"Mismatch in line {}. Expected: '{}' found '{}' (diff: {})",
line, nominal, actual, score
)),
_ => None,
})
.collect();
Expand All @@ -632,17 +649,25 @@ pub(crate) fn create_html(
.unwrap_or_default()
}
ComparisonMode::PDFText(_) => {
let diffs: Vec<(&usize, &f64)> = file
.detail
.iter()
.filter_map(|r| match r {
DiffDetail::Text { line, score } => {
//TODO: displayed line should be + 1
Some((line, score)) //TODO: want the text difference
}
_ => None,
})
.collect();
let diffs: Vec<(&usize, String)> =
file.detail
.iter()
.filter_map(|r| match r {
DiffDetail::Text {
line,
score,
actual,
nominal,
} => Some((
line,
format!(
"Mismatch in line {}. Expected: '{}' found '{}' (diff: {})",
line + 1, nominal, actual, score
),
)),
_ => None,
})
.collect();

write_pdf_detail(&file.nominal_file, &file.actual_file, &diffs, &sub_folder)
.unwrap_or_default()
Expand Down
2 changes: 1 addition & 1 deletion src/report/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub const INDEX_TEMPLATE: &str = r###"
{% else %}
<td>
{% if file.detail_path %}
<a href="./{{ rule_report.rule.name }}/{{ file.detail_path.path_name }}/{{ detail_filename }}">{{ file.relative_file_path }}</a>
<a href="./{{ rule_report.rule.name }}/{{ file.detail_path.name }}/{{ detail_filename }}">{{ file.relative_file_path }}</a>
{% else %}
{{ file.relative_file_path }}
{% endif %}
Expand Down

0 comments on commit 7a0c164

Please sign in to comment.