Skip to content

Commit 6b7759e

Browse files
committed
Test expanded diffs through full terminal rendering
1 parent 019bf12 commit 6b7759e

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use super::*;
2+
3+
#[test]
4+
fn expanded_diff_full_terminal_preserves_indentation_gutters_and_long_source() {
5+
let _guard = viewport_snapshot_test_lock();
6+
let long_source = format!(" let value = \"{}\";", "abcdefghij_".repeat(22));
7+
for centered_mode in [false, true] {
8+
for width in [40, 80, 120] {
9+
let state = TestState {
10+
display_messages: vec![DisplayMessage::tool(
11+
format!(
12+
"9- old_value();\n9+ {long_source}\n10+ nested();\n11+ done();"
13+
),
14+
crate::message::ToolCall {
15+
id: format!("expanded-frame-{width}-{centered_mode}"),
16+
name: "edit".into(),
17+
input: serde_json::json!({"file_path": "src/example.rs"}),
18+
intent: Some("Update nested code".into()),
19+
thought_signature: None,
20+
},
21+
)],
22+
messages_version: 2000 + u64::from(width) + u64::from(centered_mode),
23+
centered_mode,
24+
diff_mode_override: Some(crate::config::DiffDisplayMode::FullInline),
25+
suppress_info_widgets: true,
26+
..Default::default()
27+
};
28+
clear_test_render_state_for_tests();
29+
let mut terminal =
30+
ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, 80))
31+
.expect("terminal");
32+
terminal.draw(|frame| draw(frame, &state)).expect("draw");
33+
let buffer = terminal.backend().buffer();
34+
let rows: Vec<String> = (0..80)
35+
.map(|y| (0..width).map(|x| buffer[(x, y)].symbol()).collect())
36+
.collect();
37+
let diff_rows: Vec<&str> = rows
38+
.iter()
39+
.filter_map(|row| row.split_once("│ ").map(|(_, rest)| rest.trim_end()))
40+
.collect();
41+
assert!(rows.iter().any(|row| row.contains("╭─ diff")), "{rows:#?}");
42+
assert!(rows.iter().any(|row| row.contains("╰─")), "{rows:#?}");
43+
assert!(
44+
diff_rows.contains(&" 9 - old_value();"),
45+
"{diff_rows:#?}"
46+
);
47+
assert!(
48+
diff_rows.contains(&"10 + nested();"),
49+
"{diff_rows:#?}"
50+
);
51+
assert!(diff_rows.contains(&"11 + done();"), "{diff_rows:#?}");
52+
let mut reconstructed = String::new();
53+
let mut capturing = false;
54+
let mut continuation_count = 0;
55+
for row in &diff_rows {
56+
if let Some(source) = row.strip_prefix(" 9 + ") {
57+
capturing = true;
58+
reconstructed.push_str(source);
59+
} else if capturing {
60+
if let Some(source) = row.strip_prefix(" ↪ ") {
61+
continuation_count += 1;
62+
reconstructed.push_str(source);
63+
} else {
64+
break;
65+
}
66+
}
67+
}
68+
assert!(continuation_count > 0, "{diff_rows:#?}");
69+
assert_eq!(
70+
reconstructed, long_source,
71+
"width={width} centered={centered_mode}: {diff_rows:#?}"
72+
);
73+
println!(
74+
"width={width} centered={centered_mode}, continuations={continuation_count}:\n{}",
75+
diff_rows.join("\n")
76+
);
77+
}
78+
}
79+
}

‎crates/jcode-tui/src/tui/ui_tests/mod.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct TestState {
128128
queue_mode: bool,
129129
active_skill: Option<String>,
130130
centered_mode: bool,
131+
diff_mode_override: Option<crate::config::DiffDisplayMode>,
131132
anim_elapsed: f32,
132133
now_ms: u64,
133134
time_since_activity: Option<Duration>,
@@ -284,7 +285,8 @@ impl crate::tui::TuiState for TestState {
284285
false
285286
}
286287
fn diff_mode(&self) -> crate::config::DiffDisplayMode {
287-
crate::config::DiffDisplayMode::Inline
288+
self.diff_mode_override
289+
.unwrap_or(crate::config::DiffDisplayMode::Inline)
288290
}
289291
fn current_session_id(&self) -> Option<String> {
290292
None
@@ -517,6 +519,8 @@ mod pinned_todo_regressions;
517519
mod basic;
518520
#[path = "diagrams.rs"]
519521
mod diagrams;
522+
#[path = "expanded_diff.rs"]
523+
mod expanded_diff;
520524
#[path = "inline_picker.rs"]
521525
mod inline_picker;
522526
#[path = "onboarding.rs"]

0 commit comments

Comments
 (0)