Add terminal colors and clarify elided hierarchy branches
This commit is contained in:
parent
ed1e0595bc
commit
28b7f10f6e
1 changed files with 421 additions and 39 deletions
133
tests/review.rs
133
tests/review.rs
|
|
@ -503,7 +503,7 @@ fn unknown_records_never_produce_a_successful_equality_claim() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
||||
fn shared_hierarchy_reports_ancestors_and_each_leaf_placement_count() {
|
||||
let a = shared(square());
|
||||
let b = shared(triangle());
|
||||
let a = Document::parse(&a).unwrap();
|
||||
|
|
@ -517,7 +517,7 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
|||
" left x1 [affected]\n",
|
||||
" * leaf x2\n",
|
||||
" right x1 [affected]\n",
|
||||
" * leaf x3 [shown above]\n",
|
||||
" * leaf x3\n",
|
||||
)
|
||||
);
|
||||
let graph = diff.hierarchy(true, 8);
|
||||
|
|
@ -533,6 +533,44 @@ fn shared_hierarchy_reports_ancestors_and_marks_repeated_definitions() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii_hierarchy_marks_repeated_subtrees_and_depth_limits() {
|
||||
let bytes = layout(&[
|
||||
(
|
||||
"CHIP",
|
||||
vec![reference("left", 0, 1), reference("right", 0, 1)],
|
||||
),
|
||||
("left", vec![reference("branch", 0, 2)]),
|
||||
("right", vec![reference("branch", 0, 3)]),
|
||||
("branch", vec![reference("leaf", 0, 1)]),
|
||||
("leaf", vec![]),
|
||||
]);
|
||||
let doc = Document::parse(&bytes).unwrap();
|
||||
assert_eq!(
|
||||
doc.hierarchy(false, 8),
|
||||
concat!(
|
||||
"Hierarchy\n",
|
||||
"\"CHIP\"\n",
|
||||
" \"left\" x1\n",
|
||||
" \"branch\" x2\n",
|
||||
" \"leaf\" x1\n",
|
||||
" \"right\" x1\n",
|
||||
" \"branch\" x3 [subtree elided]\n",
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
doc.hierarchy(false, 2),
|
||||
concat!(
|
||||
"Hierarchy\n",
|
||||
"\"CHIP\"\n",
|
||||
" \"left\" x1\n",
|
||||
" \"branch\" x2 [children omitted]\n",
|
||||
" \"right\" x1\n",
|
||||
" \"branch\" x3 [children omitted]\n",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_changes_keep_unchanged_targets_and_old_edges_visible() {
|
||||
for pair in corpus()
|
||||
|
|
@ -824,6 +862,95 @@ fn cli_uses_documented_exit_codes_and_accepts_paths_with_spaces() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_color_preserves_plain_output_and_machine_formats() {
|
||||
let directory = std::env::temp_dir().join(format!("pheon color {}", 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 with_changes = |name, shape, positions: std::ops::Range<i32>| {
|
||||
let objects = positions
|
||||
.map(|x| reference("leaf", x, 1))
|
||||
.chain([shape])
|
||||
.collect();
|
||||
layout(&[("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();
|
||||
let command = || Command::new(env!("CARGO_BIN_EXE_pheon"));
|
||||
let diff = |options: &[&str]| {
|
||||
let output = command()
|
||||
.arg("diff")
|
||||
.arg(&old)
|
||||
.arg(&new)
|
||||
.args(options)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
};
|
||||
let plain = diff(&["--hierarchy", "mermaid"]);
|
||||
let colored = diff(&["--hierarchy", "mermaid", "--color=always"]);
|
||||
for span in [
|
||||
"\x1b[31m- obsolete",
|
||||
"\x1b[32m+ new",
|
||||
"\x1b[33m* CHIP",
|
||||
"\x1b[31m-2 refs",
|
||||
"\x1b[32m+3 refs",
|
||||
"\x1b[33m1 polygon changed",
|
||||
] {
|
||||
assert!(colored.contains(span), "{span:?} in {colored:?}");
|
||||
}
|
||||
let strip_ansi = |text: &str| {
|
||||
let mut parts = text.split("\x1b[");
|
||||
let mut plain = parts.next().unwrap().to_string();
|
||||
for part in parts {
|
||||
let (code, text) = part.split_once('m').unwrap();
|
||||
assert!(code.bytes().all(|b| b.is_ascii_digit() || b == b';'));
|
||||
plain.push_str(text);
|
||||
}
|
||||
plain
|
||||
};
|
||||
assert_eq!(strip_ansi(&colored), plain);
|
||||
assert_eq!(diff(&["--hierarchy", "mermaid", "--color", "never"]), plain);
|
||||
assert_eq!(
|
||||
colored.split_once("```mermaid\n").unwrap().1,
|
||||
plain.split_once("```mermaid\n").unwrap().1
|
||||
);
|
||||
assert_eq!(
|
||||
diff(&["--color", "always", "--format", "json"]),
|
||||
diff(&["--format", "json"])
|
||||
);
|
||||
|
||||
for (options, token) in [
|
||||
(&[][..], "\x1b[36mcell \"CHIP\""),
|
||||
(&["--records"][..], "\x1b[36mBGNSTR"),
|
||||
] {
|
||||
let dump = |choice| {
|
||||
let output = command()
|
||||
.arg("dump")
|
||||
.arg(&old)
|
||||
.args(options)
|
||||
.args(["--color", choice])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
};
|
||||
let colored = dump("always");
|
||||
assert!(colored.contains(token), "{colored:?}");
|
||||
assert_eq!(strip_ansi(&colored), dump("auto"));
|
||||
assert_eq!(dump("auto"), dump("never"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_decodes_gzip_by_header_and_checks_the_trailer() {
|
||||
let directory = std::env::temp_dir().join(format!("pheon gzip {}", std::process::id()));
|
||||
|
|
@ -1413,7 +1540,7 @@ fn combined_ascii_hierarchy_preserves_paths_to_changed_and_shared_cells() {
|
|||
" * changed x1 [reference changed]\n",
|
||||
" shared x1 [reference changed]\n",
|
||||
" * right x1\n",
|
||||
" shared x1 [reference changed] [shown above]\n",
|
||||
" shared x1 [reference changed]\n",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue