Skip to content

Commit 42f66a5

Browse files
committed
test(tui): simplify backtrack helper tests to spans-only fixture
1 parent 9056875 commit 42f66a5

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

codex-rs/tui/src/backtrack_helpers.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,20 @@ pub(crate) fn nth_last_user_text(
8484
mod tests {
8585
use super::*;
8686

87-
fn line(s: &str) -> Line<'static> {
88-
s.to_string().into()
89-
}
90-
91-
fn transcript_with_users(count: usize) -> (Vec<Line<'static>>, Vec<(usize, usize)>) {
92-
// Build transcript lines and user spans as [header..end) where end excludes the last body line.
93-
let mut lines: Vec<Line<'static>> = Vec::new();
94-
let mut spans: Vec<(usize, usize)> = Vec::new();
95-
for i in 0..count {
96-
// Simulate the structure produced by UserHistoryCell: blank, header, body
97-
lines.push(line(""));
98-
let header = lines.len();
99-
lines.push(line("user"));
100-
lines.push(line(&format!("message {i}")));
101-
let end = header + 1 + 1; // header + 1 (body begins) + body_len(1)
102-
spans.push((header, end));
103-
}
104-
(lines, spans)
87+
// Build absolute user message spans as [header..end) assuming the
88+
// transcript structure repeats: blank, header, 1-line body.
89+
fn user_spans_fixture(count: usize) -> Vec<(usize, usize)> {
90+
(0..count)
91+
.map(|i| {
92+
let header = 1 + i * 3; // after a leading blank per message
93+
(header, header + 2) // header + body(1)
94+
})
95+
.collect()
10596
}
10697

10798
#[test]
10899
fn normalize_wraps_to_one_when_past_oldest() {
109-
let (_, spans) = transcript_with_users(2);
100+
let spans = user_spans_fixture(2);
110101
assert_eq!(normalize_backtrack_n(&spans, 1), 1);
111102
assert_eq!(normalize_backtrack_n(&spans, 2), 2);
112103
// Requesting 3rd when only 2 exist wraps to 1
@@ -115,14 +106,14 @@ mod tests {
115106

116107
#[test]
117108
fn normalize_returns_zero_when_no_user_messages() {
118-
let (_, spans) = transcript_with_users(0);
109+
let spans = user_spans_fixture(0);
119110
assert_eq!(normalize_backtrack_n(&spans, 1), 0);
120111
assert_eq!(normalize_backtrack_n(&spans, 5), 0);
121112
}
122113

123114
#[test]
124115
fn normalize_keeps_valid_n() {
125-
let (_, spans) = transcript_with_users(3);
116+
let spans = user_spans_fixture(3);
126117
assert_eq!(normalize_backtrack_n(&spans, 2), 2);
127118
}
128119
}

0 commit comments

Comments
 (0)