mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
parent
4a385b40ff
commit
cb8fd26922
8 changed files with 234 additions and 257 deletions
|
|
@ -24,6 +24,9 @@
|
|||
fn do_thing (state: &mut Test) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_thing_arg (state: &mut Test, arg: usize) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_sub (state: &mut Test, command: TestSubcommand) -> Perhaps<Self> {
|
||||
Ok(command.execute(state)?.map(|command|Self::DoSub { command }))
|
||||
}
|
||||
|
|
@ -32,11 +35,17 @@
|
|||
fn do_other_thing (state: &mut Test) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
fn do_other_thing_arg (state: &mut Test, arg: usize) -> Perhaps<Self> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
let mut test = Test {
|
||||
keys: InputMap::new(
|
||||
"(@a do-thing) (@b do-sub do-other-thing)".into()
|
||||
)
|
||||
keys: InputMap::new("
|
||||
(@a do-thing)
|
||||
(@b do-thing-arg 0)
|
||||
(@c do-sub do-other-thing)
|
||||
(@d do-sub do-other-thing-arg 0)
|
||||
".into())
|
||||
};
|
||||
assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
kind: KeyEventKind::Press,
|
||||
|
|
@ -50,11 +59,41 @@
|
|||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE,
|
||||
})))?);
|
||||
assert_eq!(None, test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
kind: KeyEventKind::Press,
|
||||
code: KeyCode::Char('c'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE,
|
||||
})))?);
|
||||
assert_eq!(Some(true), test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
kind: KeyEventKind::Press,
|
||||
code: KeyCode::Char('d'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE,
|
||||
})))?);
|
||||
assert_eq!(None, test.handle(&TuiIn(Default::default(), Event::Key(KeyEvent {
|
||||
kind: KeyEventKind::Press,
|
||||
code: KeyCode::Char('z'),
|
||||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE,
|
||||
})))?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_dsl_context () {
|
||||
use crate::dsl::Value;
|
||||
|
||||
struct Test;
|
||||
#[tengri_proc::expose]
|
||||
impl Test {
|
||||
fn some_bool (&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
assert_eq!(Test.get(&Value::Sym(":false")), Some(false));
|
||||
assert_eq!(Test.get(&Value::Sym(":true")), Some(true));
|
||||
assert_eq!(Test.get(&Value::Sym(":some-bool")), Some(true));
|
||||
assert_eq!(Test.get(&Value::Sym(":missing-bool")), None);
|
||||
assert_eq!(Test.get(&Value::Num(0)), Some(false));
|
||||
assert_eq!(Test.get(&Value::Num(1)), Some(true));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue