From c6532f590c49505fe5e7bb39bdd69ed0816d3fdf Mon Sep 17 00:00:00 2001 From: vasilito Date: Tue, 7 Jul 2026 16:44:05 +0300 Subject: [PATCH] =?UTF-8?q?W68:=20Viewer=20tests=20=E2=80=94=20search=20op?= =?UTF-8?q?posite=20+=20bookmark=20marker=20wrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../recipes/tui/tlc/source/src/viewer/mod.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/local/recipes/tui/tlc/source/src/viewer/mod.rs b/local/recipes/tui/tlc/source/src/viewer/mod.rs index aaf8b45cd0..b82ce61ab8 100644 --- a/local/recipes/tui/tlc/source/src/viewer/mod.rs +++ b/local/recipes/tui/tlc/source/src/viewer/mod.rs @@ -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() } }