tawasuyu

tawasuyu/llimphi

Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.

Rust 660Markdown 302TOML 157RON 312382 Definitions

⎇ main modules/bookmarks/tests/smoke.rs Rust · 94 lines · 3.4 KB History Who touched what raw

chore: refresco desde el monorepo — 128 miembros, los 76 widgets y los 11 módulos b3f12e136 · Sergio ·

1//! Smoke tests del modulo bookmarks: toggle, jump-next/prev,
2//! shortcuts, fuzzy refilter del overlay.
3
4use std::path::PathBuf;
5
6use llimphi_module_bookmarks::{
7    self as bm, BookmarksAction, BookmarksMsg, BookmarksOverlay, BookmarksState,
8};
9use llimphi_compositor::{Key, KeyEvent, KeyState, Modifiers};
10
11fn key_with(ctrl: bool, alt: bool, shift: bool, ch: &str) -> KeyEvent {
12    KeyEvent {
13        key: Key::Character(ch.into()),
14        state: KeyState::Pressed,
15        text: Some(ch.into()),
16        modifiers: Modifiers { ctrl, alt, shift, ..Modifiers::default() },
17        repeat: false,
18    }
19}
20
21#[test]
22fn toggle_agrega_y_remueve() {
23    let mut s = BookmarksState::new();
24    let p = PathBuf::from("/x/foo.rs");
25    let a1 = bm::apply(&mut s, BookmarksMsg::ToggleAt { path: p.clone(), line: 5 });
26    assert!(matches!(a1, BookmarksAction::SetStatus(_)));
27    assert!(s.contains(&p, 5));
28    let a2 = bm::apply(&mut s, BookmarksMsg::ToggleAt { path: p.clone(), line: 5 });
29    assert!(matches!(a2, BookmarksAction::SetStatus(_)));
30    assert!(!s.contains(&p, 5));
31}
32
33#[test]
34fn jump_next_wraparound() {
35    let mut s = BookmarksState::new();
36    let a = PathBuf::from("/x/a.rs");
37    let b = PathBuf::from("/x/b.rs");
38    s.toggle(a.clone(), 10);
39    s.toggle(b.clone(), 20);
40    s.toggle(a.clone(), 30);
41    // Estamos en (a, 10) - next debe ser (b, 20).
42    let action = bm::apply(&mut s, BookmarksMsg::JumpNext { current_path: a.clone(), current_line: 10 });
43    assert_eq!(action, BookmarksAction::JumpTo { path: b.clone(), line: 20 });
44    // Estamos en (a, 30) - next wrappea a (a, 10).
45    let action = bm::apply(&mut s, BookmarksMsg::JumpNext { current_path: a.clone(), current_line: 30 });
46    assert_eq!(action, BookmarksAction::JumpTo { path: a.clone(), line: 10 });
47}
48
49#[test]
50fn jump_prev_wraparound() {
51    let mut s = BookmarksState::new();
52    let a = PathBuf::from("/x/a.rs");
53    s.toggle(a.clone(), 10);
54    s.toggle(a.clone(), 20);
55    s.toggle(a.clone(), 30);
56    // Estamos en (a, 10) - prev wrappea a (a, 30).
57    let action = bm::apply(&mut s, BookmarksMsg::JumpPrev { current_path: a.clone(), current_line: 10 });
58    assert_eq!(action, BookmarksAction::JumpTo { path: a.clone(), line: 30 });
59}
60
61#[test]
62fn jump_sin_marks_es_setstatus() {
63    let mut s = BookmarksState::new();
64    let action = bm::apply(&mut s, BookmarksMsg::JumpNext { current_path: PathBuf::from("/x"), current_line: 0 });
65    assert!(matches!(action, BookmarksAction::SetStatus(_)));
66}
67
68#[test]
69fn shortcuts_distinguibles() {
70    assert!(bm::toggle_shortcut(&key_with(true, true, false, "b")));
71    assert!(!bm::toggle_shortcut(&key_with(true, true, true, "b"))); // ctrl+alt+shift+b no
72    assert!(bm::open_shortcut(&key_with(true, false, true, "b")));
73    assert!(bm::next_shortcut(&key_with(true, true, false, "n")));
74    assert!(bm::prev_shortcut(&key_with(true, true, false, "p")));
75}
76
77#[test]
78fn refilter_con_query_vacio_lista_todos() {
79    let mut s = BookmarksState::new();
80    s.toggle(PathBuf::from("/x/a.rs"), 1);
81    s.toggle(PathBuf::from("/x/b.rs"), 2);
82    s.overlay = Some(BookmarksOverlay::new());
83    bm::refilter_overlay(&mut s);
84    assert_eq!(s.overlay.as_ref().unwrap().results.len(), 2);
85}
86
87#[test]
88fn clear_all_vacia_marks() {
89    let mut s = BookmarksState::new();
90    s.toggle(PathBuf::from("/x"), 1);
91    s.toggle(PathBuf::from("/y"), 2);
92    let _ = bm::apply(&mut s, BookmarksMsg::ClearAll);
93    assert!(s.marks.is_empty());
94}