Share GDSII reader logic and simplify review output

Share record framing, name decoding, payload validation, array reference
decoding, and Arrow cell-header parsing. Accept trailing NUL padding in
names and retain located diagnostics for malformed records.

Summarize text diffs by cell, layer, and reference target. Show comparison
and omission counts before detail. Compact canonical dumps while
preserving exact fields and duplicate counts for Git textconv. Simplify
hierarchy output and retain per-object evidence in JSON.
This commit is contained in:
Jan Petykiewicz 2026-11-17 21:49:26 -08:00
commit 15e8a3b7b5
9 changed files with 1717 additions and 828 deletions

View file

@ -160,7 +160,7 @@
"replacements": [
{
"added": "c0:new:0",
"explanation": "BOUNDARY modified; coordinate bounds unchanged",
"explanation": "1/0: polygon vertices changed (4 -> 3 vertices)",
"field_changes": [
{
"after": {

View file

@ -1,9 +1,4 @@
profile pheon-structural-v1
scope top=all cell=all layer=all
coordinates: integer database units; bounds: coordinate envelopes
HEADER=[600]
LIBNAME="test"
UNITS=[0.001, 1e-9] raw=0x3e4189374bc6a7f03944b82fa09b5a54
layer 1/0 name="WG"
library "test" (GDSII 600, 0.001 user units/dbu, 1e-9 m/dbu)
1/0: name "WG"
cell "CHIP"
BOUNDARY layer=1 datatype=0 xy=[0, 0, 0, 10, 10, 10, 10, 0, 0, 0]
1/0: rectangle (0, 0) to (10, 10)

View file

@ -1,7 +1,3 @@
profile pheon-structural-v1
scope top=all cell=all layer=all
cell "CHIP" old@Some(62) new@Some(62)
~ BOUNDARY modified; coordinate bounds unchanged
- @98 bbox=Some([0, 0, 10, 10]) BOUNDARY layer=1 datatype=0 xy=[0, 0, 0, 10, 10, 10, 10, 0, 0, 0]
+ @98 bbox=Some([0, 0, 10, 10]) BOUNDARY layer=1 datatype=0 xy=[0, 0, 0, 10, 10, 0, 0, 0]
1 changed cells; 2 of 2 object changes shown; 0 layer-name changes
Different · 1 changed cell · 1 removed, 1 added
cell "CHIP"
1/0: 1 polygon changed

View file

@ -1,5 +1,4 @@
flowchart TD
%% scope top=all cell=all layer=all
n0["CHIP [affected]"]
n1["leaf [cell changed]"]
n2["left [affected]"]

View file

@ -1,5 +1,5 @@
scope top=all cell=all layer=all
"CHIP" x1 [affected]
Hierarchy
"CHIP" [affected]
"left" x1 [affected]
"leaf" x2 [cell changed]
"right" x1 [affected]

View file

@ -2,12 +2,14 @@ mod common;
use arrow_array::ffi::{FFI_ArrowArray, FFI_ArrowSchema};
use pheon::{
basic::ErrType,
basic::{ErrType, encode_real8},
last_error_message,
library::{read_library, read_selected_library, scan_library},
read_bytes, read_cells_bytes,
record::RecordHeader,
records, scan_bytes,
records,
review::{Comparison, Document, dump_records},
scan_bytes,
};
use std::ffi::CStr;
@ -126,6 +128,136 @@ fn invalid_utf8_returns_located_parse_errors_in_each_reader() {
}
}
#[test]
fn extra_name_padding_is_ignored_by_comparison_and_arrow_readers() {
let (mut bytes, (start, end)) = fixture();
let target = payload_range(&bytes, records::RTAG_SNAME);
bytes[target].copy_from_slice(b"leaf");
bytes.truncate(end as usize);
common::record(&mut bytes, records::RTAG_BGNSTR, &[0; 24]);
common::record(&mut bytes, records::RTAG_STRNAME, b"leaf");
common::record(&mut bytes, records::RTAG_ENDSTR, &[]);
common::record(&mut bytes, records::RTAG_ENDLIB, &[]);
let mut padded = bytes.clone();
for tag in [
records::RTAG_LIBNAME,
records::RTAG_STRNAME,
records::RTAG_SNAME,
] {
let payload = payload_range(&padded, tag);
let mut data = padded[payload.clone()].to_vec();
data.extend_from_slice(&[0; 2]);
let mut record = Vec::new();
common::record(&mut record, tag, &data);
padded.splice(payload.start - 4..payload.end, record);
}
let baseline = Document::parse(&bytes).unwrap();
let document = Document::parse(&padded).unwrap();
assert_eq!(document.cells["töp"].objects.len(), 2);
assert!(
Comparison::between(&baseline, &document)
.outcome()
.is_equal()
);
let full = read_library(&padded).unwrap().1;
let scan = scan_library(&padded).unwrap().1;
let ranges = [(start + 2, end + 6), (end + 6, padded.len() as u64 - 4)];
let selected = read_selected_library(&padded, &ranges).unwrap().1;
let expected = read_library(&bytes).unwrap().1;
for actual in [&full, &scan, &selected] {
for field in ["lib_name", "cell_names"] {
assert_eq!(actual.column_by_name(field), expected.column_by_name(field));
}
}
assert_eq!(&full, &selected);
}
#[test]
fn interior_nuls_in_names_are_rejected_by_comparison_and_arrow_readers() {
let (bytes, range) = fixture();
for tag in [
records::RTAG_LIBNAME,
records::RTAG_STRNAME,
records::RTAG_SNAME,
] {
let mut malformed = bytes.clone();
let payload = payload_range(&malformed, tag);
malformed[payload.start] = 0;
let offset = if tag == records::RTAG_LIBNAME {
payload_range(&malformed, records::RTAG_UNITS).end
} else {
payload.end
};
let message = "name contains an embedded NUL";
check_read_errors(&malformed, range, offset, message, true);
assert_eq!(
Document::parse(&malformed).unwrap_err(),
format!("at byte {}: {message}", payload.start - 4)
);
}
}
#[test]
fn malformed_record_frames_are_rejected_at_the_same_offset() {
let (bytes, range) = fixture();
// STRING also exercises framing in the Arrow scan's geometry skip path.
for tag in [
records::RTAG_STRNAME,
records::RTAG_XY,
records::RTAG_STRING,
] {
let start = payload_range(&bytes, tag).start - 4;
for (size, message) in [
(2_u16, "Record size 2 is smaller than its header"),
(5, "odd record length"),
(u16::MAX - 1, "truncated record"),
] {
let mut malformed = bytes.clone();
malformed[start..start + 2].copy_from_slice(&size.to_be_bytes());
check_read_errors(&malformed, range, start, message, true);
assert_eq!(
dump_records(&malformed).unwrap_err(),
format!("at byte {start}: {message}")
);
}
}
}
#[test]
fn nonpositive_unit_scales_are_rejected_by_comparison_and_arrow_readers() {
let (bytes, range) = fixture();
let units = payload_range(&bytes, records::RTAG_UNITS);
let message = "UNITS must be positive finite values";
for field in [units.start, units.start + 8] {
for scale in [0.0, -1.0] {
let mut malformed = bytes.clone();
malformed[field..field + 8]
.copy_from_slice(&encode_real8(scale).unwrap().to_be_bytes());
check_read_errors(&malformed, range, units.start, message, true);
assert_eq!(
Document::parse(&malformed).unwrap_err(),
format!("at byte {}: {message}", units.start - 4)
);
}
}
}
#[test]
fn coordinate_payloads_require_whole_pairs() {
let (mut bytes, (start, end)) = fixture();
let after_text = payload_range(&bytes, records::RTAG_TEXT).end;
let xy = payload_range(&bytes[after_text..], records::RTAG_XY);
let payload_start = after_text + xy.start;
let mut replacement = Vec::new();
common::record(&mut replacement, records::RTAG_XY, &[0; 12]);
bytes.splice(payload_start - 4..after_text + xy.end, replacement);
let message = "XY payload must contain whole coordinate pairs";
check_read_errors(&bytes, (start, end + 4), payload_start, message, false);
assert!(Document::parse(&bytes).unwrap_err().contains(message));
}
#[test]
fn large_invalid_utf8_strings_do_not_dump_their_contents() {
let (mut bytes, range) = fixture();

View file

@ -52,10 +52,14 @@ fn gzip(data: &[u8]) -> Vec<u8> {
}
fn polygon(points: &[[i32; 2]]) -> Vec<u8> {
ring(RTAG_BOUNDARY, RTAG_DATATYPE, 1, points)
}
fn ring(kind: u16, type_tag: u16, layer: u16, points: &[[i32; 2]]) -> Vec<u8> {
let mut bytes = Vec::new();
record(&mut bytes, RTAG_BOUNDARY, &[]);
record(&mut bytes, RTAG_LAYER, &1_u16.to_be_bytes());
record(&mut bytes, RTAG_DATATYPE, &0_u16.to_be_bytes());
record(&mut bytes, kind, &[]);
record(&mut bytes, RTAG_LAYER, &layer.to_be_bytes());
record(&mut bytes, type_tag, &0_u16.to_be_bytes());
xy(&mut bytes, points);
record(&mut bytes, RTAG_ENDEL, &[]);
bytes
@ -312,9 +316,7 @@ fn canonical_polygon_dump_is_readable_and_offsets_are_separate() {
let doc = Document::parse(&bytes).unwrap();
let dump = doc.canonical_dump();
assert!(
dump.ends_with(
"cell \"CHIP\"\n BOUNDARY layer=1 datatype=0 xy=[0, 0, 0, 10, 10, 10, 10, 0, 0, 0]\n"
),
dump.ends_with("cell \"CHIP\"\n 1/0: rectangle (0, 0) to (10, 10)\n"),
"{dump}"
);
assert!(!dump.contains("BGNSTR"));
@ -323,6 +325,44 @@ fn canonical_polygon_dump_is_readable_and_offsets_are_separate() {
.contains("0000000000 0002 HEADER size=6 [600]")
);
assert!(doc.record_dump().contains("BGNSTR"));
let notched = polygon(&[[0, 0], [0, 3], [2, 3], [2, 2], [3, 2], [3, 0], [0, 0]]);
let bytes = layout(&[("CHIP", vec![notched])]);
let dump = Document::parse(&bytes).unwrap().canonical_dump();
assert!(
dump.ends_with(concat!(
" 1/0: polygon xy=[(0, 0), (0, 3), (2, 3), (2, 2),\n",
" (3, 2), (3, 0), (0, 0)]\n",
)),
"{dump}"
);
}
#[test]
fn canonical_dump_counts_duplicates_by_normalized_object_within_each_cell() {
let test_layout = |copies: usize| {
let mut objects = vec![square(); copies - 1];
objects.push(polygon(&[[10, 10], [10, 0], [0, 0], [0, 10], [10, 10]]));
objects.push(with_property(square(), "marked"));
layout(&[("A", objects), ("B", vec![square()])])
};
let a = test_layout(3);
let b = test_layout(2);
let a = Document::parse(&a).unwrap();
let b = Document::parse(&b).unwrap();
let dump = a.canonical_dump();
assert!(
dump.ends_with(concat!(
"cell \"A\"\n",
" 3x 1/0: rectangle (0, 0) to (10, 10)\n",
" 1/0: rectangle (0, 0) to (10, 10) property[17]=\"marked\"\n",
"cell \"B\"\n",
" 1/0: rectangle (0, 0) to (10, 10)\n",
)),
"{dump}"
);
assert!(b.canonical_dump().contains(" 2x 1/0: rectangle"));
assert_ne!(dump, b.canonical_dump());
assert_eq!(Comparison::between(&a, &b).outcome().exit_code(), 1);
}
#[test]
@ -442,7 +482,9 @@ fn unknown_records_never_produce_a_successful_equality_claim() {
assert!(!diff.outcome().is_equal());
assert_eq!(diff.outcome().exit_code(), 2);
assert!(doc.record_dump().contains("7f00"));
assert!(diff.text(0).contains("INCOMPLETE"));
let text = diff.text(0);
assert!(text.starts_with("Incomplete\nDiagnostics\n"));
assert!(text.contains("unsupported record 0x7f00"));
}
#[test]
@ -455,8 +497,8 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
assert_eq!(
diff.hierarchy(false, 8),
concat!(
"scope top=all cell=all layer=all\n",
"\"CHIP\" x1 [affected]\n",
"Hierarchy\n",
"\"CHIP\" [affected]\n",
" \"left\" x1 [affected]\n",
" \"leaf\" x2 [cell changed]\n",
" \"right\" x1 [affected]\n",
@ -510,7 +552,7 @@ fn same_bounds_changes_and_truncated_reports_remain_differences() {
diff.cells[0].removed[0].bounds,
diff.cells[0].added[0].bounds
);
assert!(diff.text(0).contains("0 of 2 object changes shown"));
assert!(diff.text(0).contains("Showing 0 of 2 object changes"));
assert_eq!(diff.outcome().exit_code(), 1);
assert!(diff.cells[0].removed[0].offset > 0);
}
@ -539,7 +581,10 @@ fn unit_changes_report_values_without_claiming_geometry_equivalence() {
..
}]
));
assert!(diff.text(0).contains("UNITS changed"));
let text = diff.text(0);
assert!(text.contains("library UNITS [0.001, 1e-9] -> [0.001, 2e-9]"));
assert!(text.contains("Coordinates use each file's database units"));
assert!(!text.contains("raw="));
assert!(diff.cells.is_empty());
}
@ -669,6 +714,7 @@ fn cli_uses_documented_exit_codes_and_accepts_paths_with_spaces() {
let command = || Command::new(env!("CARGO_BIN_EXE_pheon"));
let equal = command().arg("diff").arg(&old).arg(&old).output().unwrap();
assert_eq!(equal.status.code(), Some(0));
assert_eq!(equal.stdout, b"Equal\n");
let diff = command()
.arg("diff")
.arg(&old)
@ -678,8 +724,9 @@ fn cli_uses_documented_exit_codes_and_accepts_paths_with_spaces() {
.unwrap();
assert_eq!(diff.status.code(), Some(1));
let text = String::from_utf8(diff.stdout).unwrap();
assert!(text.contains("0 of 2 object changes shown"));
assert!(text.contains("```mermaid\nflowchart TD"));
assert!(text.contains("Showing 0 of 2 object changes"));
assert!(text.contains("Hierarchy\n```mermaid\nflowchart TD"));
assert!(!text.contains("scope top=all"));
let dump = command()
.arg("dump")
.arg(&old)
@ -921,7 +968,7 @@ fn scope_selection_distinguishes_reachable_subtrees_from_exact_cells() {
["CHIP", "leaf"]
);
assert_eq!(Comparison::between(&old, &new).cells.len(), 1);
assert!(old.canonical_dump().contains("scope top=\"CHIP\""));
assert!(old.canonical_dump().contains("Scope top=\"CHIP\"\n"));
let cell = Scope {
cell: Some("CHIP".to_string()),
..Scope::default()
@ -1058,11 +1105,99 @@ fn display_filters_never_change_equality_or_totals() {
layer: Some((42, 0)),
},
);
assert!(text.contains("display-only"));
assert!(text.contains("0 of 2 object changes shown"));
assert!(text.starts_with("Different · 1 changed cell · 1 removed, 1 added\n"));
assert!(text.contains("Display filter layer=42/0\n"));
assert!(text.contains("Showing 0 of 2 object changes (2 filtered out)"));
assert!(!text.contains("cell \"CHIP\""));
assert_eq!(diff.outcome().exit_code(), 1);
}
#[test]
fn text_hides_empty_headings_and_counts_filtered_and_limited_changes() {
use pheon::review::selection::DisplayFilter;
let mut attributes = Vec::new();
record(&mut attributes, RTAG_STRCLASS, &[0, 1]);
let a = layout(&[
("changed", vec![square()]),
("other", vec![square()]),
("gone", vec![square(), triangle()]),
("header", vec![]),
]);
let b = layout(&[
("changed", vec![triangle()]),
("other", vec![triangle()]),
("new", vec![square()]),
("empty", vec![]),
("header", vec![attributes]),
]);
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
let text = diff.text(0);
assert!(text.contains("cell \"gone\" (removed, 2 objects)\n"));
assert!(text.contains("cell \"new\" (added, 1 object)\n"));
assert!(text.contains("cell \"empty\" (added, 0 objects)\n"));
assert!(text.contains("cell \"header\" (attributes changed)\n"));
assert!(!text.contains("cell \"changed\""));
assert!(text.contains("Showing 0 of 7 object changes (7 over the limit)"));
let text = diff.text_filtered(
1,
&DisplayFilter {
cell: Some("changed".to_string()),
layer: Some((1, 0)),
},
);
assert!(text.contains(concat!(
"Display filter cell=\"changed\" layer=1/0\n",
"Showing 1 of 7 object changes (5 filtered out, 1 over the limit)\n",
"4 cell-level changes filtered out\n",
"cell \"changed\"\n 1/0: 1 rectangle removed",
)));
assert!(!text.contains("cell \"other\""));
assert!(!text.contains("cell \"new\""));
}
#[test]
fn reference_summaries_group_whole_cells_and_keep_full_placements_in_dumps() {
let empty = layout(&[("leaf", vec![]), ("other", vec![])]);
let with_chip = layout(&[
(
"CHIP",
vec![
reference("leaf", 0, 1),
reference("leaf", 5, 1),
reference("leaf", 2, 2),
reference("other", 10, 1),
],
),
("leaf", vec![]),
("other", vec![]),
]);
let existing_chip = layout(&[("CHIP", vec![]), ("leaf", vec![]), ("other", vec![])]);
let empty = Document::parse(&empty).unwrap();
let with_chip = Document::parse(&with_chip).unwrap();
let existing_chip = Document::parse(&existing_chip).unwrap();
for (old, new, sign) in [(&empty, &with_chip, "+"), (&with_chip, &empty, "-")] {
let diff = Comparison::between(old, new);
let text = diff.text(100);
assert!(text.contains(&format!(
" {sign} 2 references, 1 array reference to \"leaf\" (4 placements)\n"
)));
assert!(text.contains(&format!(" {sign} 1 reference to \"other\"\n")));
assert!(!text.contains("xy="));
let limited = diff.text(2);
assert!(limited.contains(&format!(" {sign} 2 references to \"leaf\"\n")));
assert!(limited.contains("Showing 2 of 4 object changes (2 over the limit)"));
}
let text = Comparison::between(&existing_chip, &with_chip).text(100);
assert!(text.contains(" + reference \"leaf\" xy=(0, 0)\n"));
let dump = with_chip.canonical_dump();
assert!(dump.contains(" reference \"leaf\" xy=(5, 0)\n"));
assert!(dump.contains(" array reference \"leaf\" (2 × 1) xy=[(2, 0), (102, 0), (2, 0)]\n"));
}
#[test]
fn git_external_driver_handles_changes_additions_deletions_and_errors() {
let directory = std::env::temp_dir().join(format!(
@ -1130,7 +1265,7 @@ fn git_external_driver_handles_changes_additions_deletions_and_errors() {
assert!(
String::from_utf8(changed.stdout)
.unwrap()
.contains("2 of 2 object changes shown")
.contains("Different · 1 changed cell · 1 removed, 1 added")
);
fs::write(&path, b"invalid").unwrap();
let invalid = Command::new("git")
@ -1169,7 +1304,10 @@ fn git_external_driver_handles_changes_additions_deletions_and_errors() {
let result = git(&["diff", "--cached", "--find-renames"]);
let text = String::from_utf8(result.stdout).unwrap();
assert!(text.contains("renamed layout.gds"), "{text}");
assert!(text.contains("2 of 2 object changes shown"), "{text}");
assert!(
text.contains("Different · 1 changed cell · 1 removed, 1 added"),
"{text}"
);
git(&["commit", "-qm", "rename fixture"]);
fs::write(directory.join(".gitattributes"), "*.gds diff=pheon-text\n").unwrap();
fs::write(&renamed, shared(square())).unwrap();
@ -1177,7 +1315,7 @@ fn git_external_driver_handles_changes_additions_deletions_and_errors() {
assert!(
String::from_utf8(result.stdout)
.unwrap()
.contains("- BOUNDARY")
.contains("- 1/0: polygon")
);
fs::remove_dir_all(directory).unwrap();
}
@ -1197,21 +1335,130 @@ fn replacement_explanations_are_unique_and_keep_full_evidence() {
let diff = Comparison::between(&old, &new);
assert_eq!(diff.cells[0].replacements.len(), 1);
let text = diff.text(100);
assert!(text.contains(" ~ "));
assert!(text.contains(" - @"));
assert!(text.contains(" + @"));
match pair.name {
"moved reference" => assert!(text.contains("delta=(5, 0) dbu")),
"array count" => assert!(text.contains("columns/rows 2 x 1 -> 3 x 1")),
"moved reference" => {
assert!(text.contains(" ~ reference \"leaf\" moved by (5, 0) dbu\n"))
}
"array count" => {
assert!(text.contains(" ~ array reference \"leaf\" columns/rows 2 x 1 -> 3 x 1\n"))
}
_ => assert_eq!(text, include_str!("golden/review-diff.txt")),
}
assert!(!text.contains(" - "));
assert!(!text.contains(" + "));
assert!(!text.contains("bbox="));
assert!(!diff.text(0).contains(" ~ "));
assert!(diff.text(1).contains("1 of 2 object changes shown"));
assert!(diff.text(1).contains("Showing 1 of 2 object changes"));
}
let a = layout(&[("CHIP", vec![square(), square()])]);
let b = layout(&[("CHIP", vec![triangle(), triangle()])]);
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
assert!(diff.cells[0].replacements.is_empty());
let text = diff.text(100);
assert!(text.contains(" 1/0: 2 rectangles removed · 2 polygons added\n"));
assert!(!text.contains("bbox="));
assert!(!text.contains("xy="));
}
#[test]
fn polygon_diff_reports_moves_and_other_changes_without_individual_geometry() {
let before = layout(&[("CHIP", vec![with_property(square(), "old")])]);
let before = Document::parse(&before).unwrap();
for (shape, label) in [
(
polygon(&[[-5, 2], [5, 2], [5, 12], [-5, 12], [-5, 2]]),
"1 rectangle changed",
),
(
polygon(&[[0, 0], [20, 0], [20, 10], [0, 10], [0, 0]]),
"1 rectangle changed",
),
(
polygon(&[[5, 0], [10, 5], [5, 10], [0, 5], [5, 0]]),
"1 polygon changed",
),
(square(), "1 rectangle changed"),
] {
let after = layout(&[("CHIP", vec![with_property(shape, "new")])]);
let after = Document::parse(&after).unwrap();
let diff = Comparison::between(&before, &after);
let text = diff.text(100);
assert!(text.contains(&format!(" 1/0: {label}\n")), "{text}");
assert!(!text.contains("dbu"));
assert!(!text.contains("bbox="));
assert!(!text.contains("xy="));
}
for (shape, shifted, name) in [
(
triangle(),
polygon(&[[2, -1], [12, -1], [2, 9], [2, -1]]),
"polygon",
),
(
square(),
polygon(&[[2, -1], [12, -1], [12, 9], [2, 9], [2, -1]]),
"rectangle",
),
] {
let before = layout(&[("CHIP", vec![shape])]);
let after = layout(&[("CHIP", vec![shifted])]);
let diff = Comparison::between(
&Document::parse(&before).unwrap(),
&Document::parse(&after).unwrap(),
);
assert!(diff.text(100).contains(&format!(" 1/0: 1 {name} moved\n")));
}
}
#[test]
fn polygon_diff_groups_shapes_by_layer_across_dimensions() {
let shapes = [
square(),
polygon(&[[30, 0], [50, 0], [50, 5], [30, 5], [30, 0]]),
polygon(&[[70, 0], [80, 0], [71, 9], [70, 0]]),
ring(
RTAG_BOUNDARY,
RTAG_DATATYPE,
2,
&[[0, 0], [10, 0], [0, 10], [0, 0]],
),
];
let layout_with_property = |value| {
let objects = shapes
.iter()
.map(|shape| with_property(shape.clone(), value))
.collect();
layout(&[("CHIP", objects)])
};
let before = layout_with_property("old");
let after = layout_with_property("new");
let diff = Comparison::between(
&Document::parse(&before).unwrap(),
&Document::parse(&after).unwrap(),
);
assert_eq!(
diff.text(100),
concat!(
"Different · 1 changed cell · 4 removed, 4 added\n",
"cell \"CHIP\"\n",
" 1/0: 2 rectangles, 1 polygon changed\n",
" 2/0: 1 polygon changed\n",
)
);
}
#[test]
fn polygon_diff_distinguishes_boxes_from_rectangular_boundaries() {
let before = layout(&[("CHIP", vec![square()])]);
let points = [[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]];
let after = layout(&[("CHIP", vec![ring(RTAG_BOX, RTAG_BOXTYPE, 1, &points)])]);
let diff = Comparison::between(
&Document::parse(&before).unwrap(),
&Document::parse(&after).unwrap(),
);
let text = diff.text(100);
assert!(text.contains(" 1/0: 1 rectangle removed · 1 box added\n"));
}
#[test]
@ -1231,7 +1478,21 @@ fn path_width_explanation_preserves_absent_and_zero() {
let a = path(None);
let b = path(Some(0));
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
assert!(diff.text(100).contains("width absent -> 0 dbu"));
assert!(
diff.text(100)
.contains(" ~ 1/0: path width absent -> 0 dbu\n")
);
}
#[test]
fn label_replacements_show_only_changed_fields() {
let a = layout(&[("CHIP", vec![label((2, 0), "old")])]);
let b = layout(&[("CHIP", vec![label((2, 0), "new")])]);
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
assert_eq!(
diff.text(100),
"Different · 1 changed cell · 1 removed, 1 added\ncell \"CHIP\"\n ~ 2/0: label text \"old\" -> \"new\"\n"
);
}
#[test]
@ -1250,8 +1511,20 @@ fn unchanged_layer_names_explain_geometry_changes_once() {
let b = named(triangle());
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
let text = diff.text(100);
assert_eq!(text.matches("name=\"WG\"").count(), 1);
assert_eq!(text.matches("1/0: name \"WG\"").count(), 1);
assert!(diff.layer_names.is_empty());
let names = corpus()
.into_iter()
.find(|case| case.name == "layer name only")
.unwrap();
let old = Document::parse(&names.old).unwrap();
let new = Document::parse(&names.new).unwrap();
assert!(
Comparison::between(&old, &new)
.text(0)
.contains("1/0: name \"WG\" -> \"CORE:WG\"")
);
}
#[test]
@ -1261,19 +1534,11 @@ fn library_presence_changes_distinguish_empty_and_absent_revisions() {
let absent = doc.empty_like();
let added = Comparison::between(&absent, &doc);
assert_eq!(added.outcome().exit_code(), 1);
assert!(
added
.text(0)
.contains("library presence: [\"absent\"] -> [\"present\"]\n")
);
assert!(!added.text(0).contains("equal under"));
assert!(added.text(0).contains("library added\n"));
assert!(added.text(0).starts_with("Different · 1 library change\n"));
let removed = Comparison::between(&doc, &absent);
assert_eq!(removed.outcome().exit_code(), 1);
assert!(
removed
.text(0)
.contains("library presence: [\"present\"] -> [\"absent\"]\n")
);
assert!(removed.text(0).contains("library removed\n"));
}
#[test]

View file

@ -75,7 +75,7 @@ fn comparison_reports_survive_dropped_documents_and_overwritten_inputs() {
assert_eq!(limited["hierarchy"], actual["hierarchy"]);
assert_eq!(limited["summary"], actual["summary"]);
assert_eq!(limited["exit_code"], 1);
assert!(comparison.text(0).contains("0 of 2 object changes shown"));
assert!(comparison.text(0).contains("Showing 0 of 2 object changes"));
}
#[test]
@ -118,9 +118,10 @@ fn comparison_diagnostics_capture_both_sides_and_scope_mismatch_once() {
assert_eq!(report["diagnostics"][1]["side"], "new");
assert_eq!(report["diagnostics"][2]["code"], "scope_mismatch");
let text = comparison.text(0);
let scope = text.find("INCOMPLETE: comparison scopes differ").unwrap();
let old = text.find("INCOMPLETE: old:").unwrap();
let new = text.find("INCOMPLETE: new:").unwrap();
assert!(text.starts_with("Incomplete\nScope cell=\"CHIP\"\nDiagnostics\n"));
let scope = text.find("\n comparison scopes differ").unwrap();
let old = text.find("\n old:").unwrap();
let new = text.find("\n new:").unwrap();
assert!(scope < old && old < new);
}
@ -259,7 +260,7 @@ fn future_layer_metadata_remains_incomplete_under_geometry_scopes() {
let diff = Comparison::between(&doc, &doc);
assert_eq!(diff.outcome().exit_code(), 2);
assert!(!diff.outcome().is_equal());
assert!(diff.text(0).contains("INCOMPLETE"));
assert!(diff.text(0).starts_with("Incomplete\n"));
let json = diff.json_report(&inputs(), &ReportOptions::default());
assert_eq!(json["status"], "incomplete");
assert_eq!(json["result"], "unknown");
@ -348,6 +349,21 @@ fn typed_evidence_preserves_defaults_properties_bytes_and_real_encodings() {
b[within..within + 8].copy_from_slice(&0x4201000000000000_u64.to_be_bytes());
let a = layout(&[("CHIP", vec![a]), ("leaf", vec![])]);
let b = layout(&[("CHIP", vec![b]), ("leaf", vec![])]);
let before = Document::parse(&a).unwrap();
let after = Document::parse(&b).unwrap();
assert!(before.canonical_dump().contains("mag=1.0 property"));
assert!(
after
.canonical_dump()
.contains("mag=1.0 raw=0x4201000000000000")
);
let text = Comparison::between(&before, &after).text(100);
assert!(text.contains("mag 1.0 raw=0x4110000000000000 -> 1.0 raw=0x4201000000000000"));
let omitted = layout(&[("CHIP", vec![reference("leaf", 0, 1)]), ("leaf", vec![])]);
let omitted = Document::parse(&omitted).unwrap();
let text = Comparison::between(&before, &omitted).text(100);
assert!(text.contains("mag 1.0 -> absent"));
assert!(!text.contains("raw="));
let r = report(&a, &b, &ReportOptions::default());
let replacement = &r["cell_changes"][0]["replacements"][0];
assert_eq!(replacement["match_rule"], "unique_kind_target");
@ -587,11 +603,7 @@ fn cli_preserves_non_utf8_path_bytes_and_literal_option_names() {
.output()
.unwrap();
assert_eq!(output.status.code(), Some(0));
assert!(
String::from_utf8(output.stdout)
.unwrap()
.starts_with("profile ")
);
assert_eq!(output.stdout, b"Equal\n");
}
#[test]

View file

@ -122,11 +122,41 @@ fn aref_pitches_use_wide_coordinate_differences_in_full_reads_and_scans() {
#[test]
fn aref_invalid_counts_and_unrepresentable_pitches_return_errors() {
let check_array_error = |bytes: &[u8], message: &str| {
let ranges = [(library_header().len() as u64, bytes.len() as u64 - 4)];
for result in [
read_library(bytes),
scan_library(bytes),
read_selected_library(bytes, &ranges),
] {
let (_, error) = result.unwrap_err();
assert!(matches!(error, pheon::basic::ErrType::Failed(reason)
if reason.contains(message)));
}
assert!(
pheon::review::Document::parse(bytes)
.unwrap_err()
.contains(message)
);
};
for counts in [[0, 1], [-1, 1], [1, 0], [1, -1]] {
let bytes = aref_fixture([0, 0], [10, 0], [0, 10], counts);
assert!(read_library(&bytes).is_err());
assert!(scan_library(&bytes).is_err());
check_array_error(&bytes, "AREF column and row counts must be positive");
}
let mut bytes = aref_fixture([0, 0], [10, 0], [0, 10], [1, 2]);
let xy_offset = pheon::review::Document::parse(&bytes)
.unwrap()
.records
.iter()
.find(|record| record.tag == records::RTAG_XY)
.unwrap()
.offset;
let mut replacement = Vec::new();
record(&mut replacement, records::RTAG_XY, &[0; 16]);
bytes.splice(xy_offset..xy_offset + 28, replacement);
check_array_error(&bytes, "AREF needs exactly three XY coordinate pairs");
let bytes = aref_fixture([i32::MIN, 0], [i32::MAX, 0], [i32::MIN, 10], [1, 2]);
assert!(read_library(&bytes).is_err());
assert!(scan_library(&bytes).is_err());
@ -472,7 +502,7 @@ fn selections_support_subsets_reordering_and_empty_results() {
#[test]
fn id_tables_preserve_encounter_order_and_selection_local_ids() {
let mut bytes = library_header();
for (name, layer, datatype) in [("zeta", 9_i16, 4_i16), ("middle", 2, 8), ("alpha", 9, 4)] {
for (name, layer, datatype) in [("zeta", 9_i16, 4_i16), ("middle", 2, 8), ("alpha\0", 9, 4)] {
record(&mut bytes, records::RTAG_BGNSTR, &[0; 24]);
record(&mut bytes, records::RTAG_STRNAME, name.as_bytes());
if name == "zeta" {