Pair unique layer-only shape changes

This commit is contained in:
Jan Petykiewicz 2026-11-18 23:16:09 -08:00
commit ab308f7b7f

View file

@ -1813,6 +1813,118 @@ fn replacement_explanations_are_unique_and_keep_full_evidence() {
assert!(!text.contains("xy="));
}
#[test]
fn layer_only_shape_replacements_keep_evidence_and_respect_selection() {
let rect = [[10, 0], [0, 0], [0, 10], [10, 10], [10, 0]];
let on_core = ring(RTAG_BOUNDARY, RTAG_DATATYPE, 2, &rect);
let named = |mut objects: Vec<Vec<u8>>, names: &[&str]| {
objects.push(label((900, 7), LAYER_SENTINEL));
objects.extend(names.iter().map(|name| label((900, 7), name)));
layout(&[("CHIP", objects)])
};
let old = named(vec![square()], &["1:0:WG", "2:0:CORE"]);
let new = named(vec![on_core.clone()], &["1:0:WG", "2:0:CORE"]);
let old = Document::parse(&old).unwrap();
let diff = Comparison::between(&old, &Document::parse(&new).unwrap());
assert_eq!(
diff.text(2),
"Different\nCells:\n* CHIP\n ~ 1/0 (WG) → 2/0 (CORE) · rectangle\n"
);
let limited = diff.text(1);
assert!(limited.contains("2 object changes over the limit"));
assert!(!limited.contains("Cells:"));
for (pair, suffix) in [
((1, 0), " 1/0 (WG): 1 rectangle removed\n"),
((2, 0), " 2/0 (CORE): 1 rectangle added\n"),
] {
let filtered = diff.text_filtered(
1,
&DisplayFilter {
cell: None,
layer: Some(pair),
},
);
assert!(filtered.contains("1 object change filtered out"));
assert!(filtered.ends_with(suffix), "{filtered}");
}
let json = diff.json_report(&Default::default(), &Default::default());
let replacement = &json["cell_changes"][0]["replacements"][0];
assert_eq!(replacement["match_rule"], "unique_layer_change");
assert_eq!(replacement["field_changes"].as_array().unwrap().len(), 1);
assert_eq!(replacement["field_changes"][0]["tag"], RTAG_LAYER);
assert_eq!(json["summary"]["removed_objects"], "1");
assert_eq!(json["summary"]["added_objects"], "1");
let old = named(vec![square()], &["1:0:WG"]);
let new = named(vec![on_core], &["2:0:CORE"]);
let diff = Comparison::between(
&Document::parse(&old).unwrap(),
&Document::parse(&new).unwrap(),
);
assert!(
diff.text(2)
.ends_with(" ~ 1/0 (WG) → 2/0 (CORE) · rectangle\n")
);
}
#[test]
fn layer_only_matching_requires_unique_shapes_and_identical_payloads() {
let core_square = ring(
RTAG_BOUNDARY,
RTAG_DATATYPE,
2,
&[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
);
for (old, new) in [
(vec![square(), square()], vec![core_square.clone()]),
(
vec![square()],
vec![core_square.clone(), core_square.clone()],
),
(vec![square()], vec![with_property(core_square, "new")]),
(
vec![square()],
vec![ring(
RTAG_BOUNDARY,
RTAG_DATATYPE,
2,
&[[0, 0], [10, 0], [0, 10], [0, 0]],
)],
),
] {
let old = layout(&[("CHIP", old)]);
let new = layout(&[("CHIP", new)]);
let diff = Comparison::between(
&Document::parse(&old).unwrap(),
&Document::parse(&new).unwrap(),
);
assert!(diff.cells[0].replacements.is_empty());
assert!(diff.text(100).contains(" removed\n"));
assert!(diff.text(100).contains(" added\n"));
}
}
#[test]
fn datatype_only_path_changes_pair_on_the_same_layer() {
let old = layout(&[("CHIP", vec![path(Some(8), &[[0, 0], [10, 10]])])]);
let old_doc = Document::parse(&old).unwrap();
let at = old_doc
.records
.iter()
.find(|record| record.tag == RTAG_DATATYPE)
.unwrap()
.offset
+ 4;
let mut new = old.clone();
new[at..at + 2].copy_from_slice(&3_u16.to_be_bytes());
let diff = Comparison::between(&old_doc, &Document::parse(&new).unwrap());
assert!(diff.text(2).ends_with(" ~ 1/0 → 1/3 · path\n"));
assert_eq!(
diff.cells[0].replacements[0].match_rule,
"unique_layer_change"
);
}
#[test]
fn polygon_diff_reports_single_displacements_and_groups_bulk_moves() {
let before = layout(&[("CHIP", vec![with_property(square(), "old")])]);