mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
#[cfg(test)] mod test_focus {
|
|
use super::focus::*;
|
|
#[test] fn test_focus () {
|
|
|
|
struct FocusTest {
|
|
focused: char,
|
|
cursor: (usize, usize)
|
|
}
|
|
|
|
impl HasFocus for FocusTest {
|
|
type Item = char;
|
|
fn focused (&self) -> Self::Item {
|
|
self.focused
|
|
}
|
|
fn set_focused (&mut self, to: Self::Item) {
|
|
self.focused = to
|
|
}
|
|
}
|
|
|
|
impl FocusGrid for FocusTest {
|
|
fn focus_cursor (&self) -> (usize, usize) {
|
|
self.cursor
|
|
}
|
|
fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
|
|
&mut self.cursor
|
|
}
|
|
fn focus_layout (&self) -> &[&[Self::Item]] {
|
|
&[
|
|
&['a', 'a', 'a', 'b', 'b', 'd'],
|
|
&['a', 'a', 'a', 'b', 'b', 'd'],
|
|
&['a', 'a', 'a', 'c', 'c', 'd'],
|
|
&['a', 'a', 'a', 'c', 'c', 'd'],
|
|
&['e', 'e', 'e', 'e', 'e', 'e'],
|
|
]
|
|
}
|
|
}
|
|
|
|
let mut tester = FocusTest { focused: 'a', cursor: (0, 0) };
|
|
|
|
tester.focus_right();
|
|
assert_eq!(tester.cursor.0, 3);
|
|
assert_eq!(tester.focused, 'b');
|
|
|
|
tester.focus_down();
|
|
assert_eq!(tester.cursor.1, 2);
|
|
assert_eq!(tester.focused, 'c');
|
|
|
|
}
|
|
}
|