use serde_json::{Value, json};
use crate::render::rendered;
#[track_caller]
fn says(frame: &Value, needles: &[&str]) {
let said = rendered(frame);
for needle in needles {
assert!(said.contains(needle), "{frame}\n-> {said}");
}
}
#[test]
fn a_work_diff_says_its_two_ends_its_totals_and_where_it_was_cut() {
let path = crate::test_support::corpus::root()
.join("answers")
.join("work-diff.json");
let frame = crate::test_support::corpus::fixture(&path)
.frames
.first()
.cloned()
.expect("the work-diff fixture carries a frame");
says(
&frame,
&[
"→ main from work/bl-3 at aaa..bbb",
"2 files +3 -1 1 binary",
"src/a.rs +3 -1",
"assets/x.png binary",
"… the engine stopped listing here",
"nothing changed on this branch yet",
"missing work/bl-2",
],
);
let said = rendered(&frame);
assert!(!said.contains("unreadable\n "), "{said}");
}
#[test]
fn one_end_alone_names_no_comparison_and_a_binary_only_row_totals_nothing() {
let said = rendered(&json!({"ok": true, "kind": "work-diff", "rows": [{
"ball_id": "bl-9", "project": "p", "state": "diff",
"target": "main", "source": "work/bl-9", "target_oid": "aaa",
"truncated": false,
"files": [{"path": "logo.png", "binary": true}]}]}));
assert!(!said.contains(" at "), "{said}");
assert!(said.contains("1 file 1 binary"), "{said}");
assert!(said.contains("logo.png binary"), "{said}");
assert!(!said.contains('+'), "{said}");
}
#[test]
fn a_wall_whose_agents_changed_nothing_says_so() {
says(
&json!({"ok": true, "kind": "work-diff", "rows": []}),
&["nothing has changed"],
);
}