Add an opt-in detailed text diff
This commit is contained in:
parent
ab308f7b7f
commit
f3275fc161
1 changed files with 266 additions and 45 deletions
120
tests/review.rs
120
tests/review.rs
|
|
@ -6,7 +6,8 @@ use common::{library_header, record};
|
|||
use pheon::{
|
||||
records::*,
|
||||
review::{
|
||||
Comparison, Document, TextComparison, names::LAYER_SENTINEL, selection::DisplayFilter,
|
||||
Comparison, Document, TextComparison, TextReportOptions, names::LAYER_SENTINEL,
|
||||
selection::DisplayFilter,
|
||||
},
|
||||
};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
|
|
@ -1006,6 +1007,107 @@ fn cli_color_preserves_plain_output_and_machine_formats() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_details_show_coordinates_and_properties_within_filters_and_limits() {
|
||||
let directory = std::env::temp_dir().join(format!("pheon-details-{}", std::process::id()));
|
||||
fs::create_dir_all(&directory).unwrap();
|
||||
struct Cleanup(PathBuf);
|
||||
impl Drop for Cleanup {
|
||||
fn drop(&mut self) {
|
||||
let _ = fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
let _cleanup = Cleanup(directory.clone());
|
||||
let old = directory.join("old.gds");
|
||||
let new = directory.join("new.gds");
|
||||
let common_ref = reference("leaf", 0, 1);
|
||||
let additional_ref = reference("leaf", 5, 1);
|
||||
let points = [[0, 0], [4, 0], [4, -5], [13, -5], [13, 9]];
|
||||
let shifted = polygon(&[[2, -1], [12, -1], [12, 9], [2, 9], [2, -1]]);
|
||||
fs::write(
|
||||
&old,
|
||||
layout(&[
|
||||
(
|
||||
"CHIP",
|
||||
vec![with_property(square(), "old"), common_ref.clone()],
|
||||
),
|
||||
("leaf", vec![]),
|
||||
("other", vec![label((2, 0), "before other")]),
|
||||
("removed", vec![label((2, 0), "payload in removed cell")]),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
&new,
|
||||
layout(&[
|
||||
(
|
||||
"CHIP",
|
||||
vec![
|
||||
with_property(shifted, "new"),
|
||||
with_property(path(Some(8), &points), "path property"),
|
||||
common_ref,
|
||||
additional_ref.clone(),
|
||||
additional_ref,
|
||||
],
|
||||
),
|
||||
("leaf", vec![]),
|
||||
("other", vec![label((2, 0), "after other")]),
|
||||
("added", vec![label((2, 0), "payload in added cell")]),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
let diff = |options: &[&str]| {
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_pheon"))
|
||||
.arg("diff")
|
||||
.arg(&old)
|
||||
.arg(&new)
|
||||
.args(options)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
output.status.code(),
|
||||
Some(1),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
};
|
||||
let detailed = diff(&["--show-cell", "CHIP", "--details", "--hierarchy", "ascii"]);
|
||||
assert!(detailed.contains(concat!(
|
||||
" ~ 1/0: rectangle\n",
|
||||
" - 1/0: rectangle (0, 0) to (10, 10) property[17]=\"old\"\n",
|
||||
" + 1/0: rectangle (2, -1) to (12, 9) property[17]=\"new\"\n",
|
||||
)));
|
||||
assert!(detailed.contains(concat!(
|
||||
" + 1/0: path width=[8] xy=[(0, 0), (4, 0), (4, -5), (13, -5),\n",
|
||||
" (13, 9)] property[17]=\"path property\"\n",
|
||||
)));
|
||||
assert!(detailed.contains(" + 2× reference \"leaf\" xy=(5, 0) · placements 1 -> 3\n"));
|
||||
assert!(!detailed.contains("Hierarchy\n"));
|
||||
assert!(!detailed.contains("after other"));
|
||||
let limited = diff(&[
|
||||
"--show-cell",
|
||||
"CHIP",
|
||||
"--details",
|
||||
"--max-changes",
|
||||
"1",
|
||||
"--hierarchy",
|
||||
"ascii",
|
||||
]);
|
||||
assert!(limited.contains("4 object changes over the limit"));
|
||||
assert!(!limited.contains("~ 1/0: rectangle"));
|
||||
assert!(!limited.contains("property[17]=\"old\""));
|
||||
assert!(limited.ends_with("Hierarchy\n* CHIP\n leaf x1 -> x3\n"));
|
||||
|
||||
let all = diff(&["--details"]);
|
||||
assert!(all.contains("Cells:\n- removed\n+ added\n* CHIP\n"));
|
||||
assert!(!all.contains("payload in"));
|
||||
assert_eq!(
|
||||
diff(&["--details", "--format", "json"]),
|
||||
diff(&["--format", "json"])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_decodes_gzip_by_header_and_checks_the_trailer() {
|
||||
let directory = std::env::temp_dir().join(format!("pheon gzip {}", std::process::id()));
|
||||
|
|
@ -1830,6 +1932,22 @@ fn layer_only_shape_replacements_keep_evidence_and_respect_selection() {
|
|||
diff.text(2),
|
||||
"Different\nCells:\n* CHIP\n ~ 1/0 (WG) → 2/0 (CORE) · rectangle\n"
|
||||
);
|
||||
assert!(
|
||||
diff.render_text_with_options(
|
||||
2,
|
||||
&Default::default(),
|
||||
true,
|
||||
TextReportOptions {
|
||||
details: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.ends_with(concat!(
|
||||
" ~ 1/0 (WG) → 2/0 (CORE) · rectangle\n",
|
||||
" - 1/0: rectangle (0, 0) to (10, 10)\n",
|
||||
" + 2/0: rectangle (0, 0) to (10, 10)\n",
|
||||
))
|
||||
);
|
||||
let limited = diff.text(1);
|
||||
assert!(limited.contains("2 object changes over the limit"));
|
||||
assert!(!limited.contains("Cells:"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue