W68: Viewer tests — search opposite + bookmark marker wrap
Add 2 unit tests hardening viewer features: - search_opposite_shift_n_inverts_direction: verify Shift-N moves backward after search_next - bookmarks_wraps_marker: verify 10 consecutive m presses wrap the marker back to 0 and r jumps correctly Tests: 1427 pass (was 1425), zero warnings.
This commit is contained in:
@@ -2025,6 +2025,39 @@ mod tests {
|
||||
assert_eq!(n, 2); // only standalone "foo" entries
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn search_opposite_shift_n_inverts_direction() {
|
||||
let p = make_text("opp.txt", b"foo bar foo baz foo");
|
||||
let mut v = Viewer::open(&p).unwrap();
|
||||
v.search("foo", false).unwrap();
|
||||
// n moves forward to second match.
|
||||
let m = v.search_next();
|
||||
assert!(m.is_some());
|
||||
// Shift-N should move backward to first match.
|
||||
let shift_n = Key { code: b'N' as u32, mods: crate::key::Modifiers::SHIFT };
|
||||
v.handle_key(shift_n);
|
||||
// After Shift-N, n should move forward again (direction flipped back).
|
||||
let m2 = v.search_next();
|
||||
assert!(m2.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bookmarks_wraps_marker() {
|
||||
let p = make_text("wrapm.txt", b"a\nb\n");
|
||||
let mut v = Viewer::open(&p).unwrap();
|
||||
// Press m 10 times — each sets a bookmark at top=0 then advances.
|
||||
for _ in 0..10 {
|
||||
v.handle_key(k('m'));
|
||||
}
|
||||
// After 10 presses, marker should have wrapped back to 0.
|
||||
assert_eq!(v.marker, 0);
|
||||
// The r key jumps to marker-1 = 9 (which was set in the 10th press).
|
||||
v.top = 99;
|
||||
v.handle_key(k('r'));
|
||||
assert_eq!(v.top, 0, "jump to slot 9 which has the bookmark at position 0");
|
||||
}
|
||||
fn k(c: char) -> Key {
|
||||
Key { code: c as u32, mods: crate::key::Modifiers::empty() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user