Fold unbranched paths in ASCII diffs
This commit is contained in:
parent
4789638e22
commit
4ae689cd1c
1 changed files with 208 additions and 33 deletions
|
|
@ -533,6 +533,48 @@ fn shared_hierarchy_reports_ancestors_and_each_leaf_placement_count() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii_diff_folds_single_placement_paths_up_to_branches_and_changed_edges() {
|
||||
let with_branch = |count, shape| {
|
||||
layout(&[
|
||||
("CHIP", vec![reference("block", 0, 1)]),
|
||||
("block", vec![reference("routing", 0, 1)]),
|
||||
("routing", vec![reference("fanout", 0, 1)]),
|
||||
(
|
||||
"fanout",
|
||||
vec![reference("left", 0, 1), reference("right", 0, 1)],
|
||||
),
|
||||
("left", vec![reference("target", 0, count)]),
|
||||
("target", vec![]),
|
||||
("right", vec![reference("unit", 0, 1)]),
|
||||
("unit", vec![reference("leaf", 0, 1)]),
|
||||
("leaf", vec![shape]),
|
||||
])
|
||||
};
|
||||
let old = with_branch(2, square());
|
||||
let new = with_branch(3, triangle());
|
||||
let diff = Comparison::between(
|
||||
&Document::parse(&old).unwrap(),
|
||||
&Document::parse(&new).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
diff.hierarchy(false, 8),
|
||||
concat!(
|
||||
"Hierarchy\n",
|
||||
"CHIP → block → routing [affected]\n",
|
||||
" fanout x1 [affected]\n",
|
||||
" * left x1\n",
|
||||
" target x2 -> x3\n",
|
||||
" right x1 → unit → * leaf\n",
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
diff.hierarchy(false, 2),
|
||||
"Hierarchy\nCHIP → block → routing [affected] [children omitted]\n"
|
||||
);
|
||||
assert!(!diff.hierarchy(true, 8).contains('→'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii_hierarchy_marks_repeated_subtrees_and_depth_limits() {
|
||||
let bytes = layout(&[
|
||||
|
|
@ -880,7 +922,13 @@ fn cli_color_preserves_plain_output_and_machine_formats() {
|
|||
.map(|x| reference("leaf", x, 1))
|
||||
.chain([shape])
|
||||
.collect();
|
||||
layout(&[("CHIP", objects), ("leaf", vec![]), (name, vec![])])
|
||||
layout(&[
|
||||
("top", vec![reference("route", 0, 1)]),
|
||||
("route", vec![reference("CHIP", 0, 1)]),
|
||||
("CHIP", objects),
|
||||
("leaf", vec![]),
|
||||
(name, vec![]),
|
||||
])
|
||||
};
|
||||
fs::write(&old, with_changes("obsolete", square(), 0..2)).unwrap();
|
||||
fs::write(&new, with_changes("new", triangle(), 10..13)).unwrap();
|
||||
|
|
@ -928,6 +976,13 @@ fn cli_color_preserves_plain_output_and_machine_formats() {
|
|||
diff(&["--color", "always", "--format", "json"]),
|
||||
diff(&["--format", "json"])
|
||||
);
|
||||
let ascii = diff(&["--hierarchy", "ascii", "--color=always"]);
|
||||
let folded = ascii
|
||||
.lines()
|
||||
.find(|line| line.starts_with("top → route → "))
|
||||
.unwrap();
|
||||
assert!(folded.contains("\x1b[33m* CHIP"));
|
||||
assert_eq!(strip_ansi(&ascii), diff(&["--hierarchy", "ascii"]));
|
||||
|
||||
for (options, token) in [
|
||||
(&[][..], "\x1b[36mcell \"CHIP\""),
|
||||
|
|
|
|||
Loading…
Reference in a new issue