data: Restore testability of action->keysym conversion
This commit is contained in:
76
src/data.rs
76
src/data.rs
@ -383,17 +383,7 @@ impl Layout {
|
||||
)}).collect();
|
||||
|
||||
let symbolmap: HashMap<String, u32> = generate_keycodes(
|
||||
button_actions.iter()
|
||||
.filter_map(|(_name, action)| {
|
||||
match action {
|
||||
::action::Action::Submit {
|
||||
text: _, keys,
|
||||
} => Some(keys),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.map(|named_keysym| named_keysym.0.as_str())
|
||||
extract_symbol_names(&button_actions)
|
||||
);
|
||||
|
||||
let button_states = button_actions.into_iter().map(|(name, action)| {
|
||||
@ -733,6 +723,22 @@ fn create_button<H: logging::Handler>(
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_symbol_names<'a>(actions: &'a [(&str, action::Action)])
|
||||
-> impl Iterator<Item=&'a str>
|
||||
{
|
||||
actions.iter()
|
||||
.filter_map(|(_name, act)| {
|
||||
match act {
|
||||
action::Action::Submit {
|
||||
text: _, keys,
|
||||
} => Some(keys),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.map(|named_keysym| named_keysym.0.as_str())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -861,6 +867,23 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Test if erase yields a useable keycode
|
||||
#[test]
|
||||
fn test_layout_erase() {
|
||||
let out = Layout::from_file(path_from_root("tests/layout_erase.yaml"))
|
||||
.unwrap()
|
||||
.build(ProblemPanic).0
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
out.views["base"].1
|
||||
.get_rows()[0].1
|
||||
.buttons[0].1
|
||||
.state.borrow()
|
||||
.keycodes.len(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parsing_fallback() {
|
||||
assert!(Layout::from_resource(FALLBACK_LAYOUT_NAME)
|
||||
@ -938,4 +961,35 @@ mod tests {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_symbols() {
|
||||
let actions = [(
|
||||
"ac",
|
||||
action::Action::Submit {
|
||||
text: None,
|
||||
keys: vec![
|
||||
action::KeySym("a".into()),
|
||||
action::KeySym("c".into()),
|
||||
],
|
||||
},
|
||||
)];
|
||||
assert_eq!(
|
||||
extract_symbol_names(&actions[..]).collect::<Vec<_>>(),
|
||||
vec!["a", "c"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_symbols_erase() {
|
||||
let actions = [(
|
||||
"Erase",
|
||||
action::Action::Erase,
|
||||
)];
|
||||
assert_eq!(
|
||||
extract_symbol_names(&actions[..]).collect::<Vec<_>>(),
|
||||
Vec::<&str>::new(), //"BackSpace"], // TODO: centralize handling of BackSpace
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ fn sorted<'a, I: Iterator<Item=&'a str>>(
|
||||
/// HACK: starting from 9, because 8 results in keycode 0,
|
||||
/// which the compositor likes to discard
|
||||
pub fn generate_keycodes<'a, C: IntoIterator<Item=&'a str>>(
|
||||
key_names: C
|
||||
key_names: C,
|
||||
) -> HashMap<String, u32> {
|
||||
let special_keysyms = ["BackSpace", "Return"].iter().map(|&s| s);
|
||||
HashMap::from_iter(
|
||||
|
||||
10
tests/layout_erase.yaml
Normal file
10
tests/layout_erase.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
# Erase only
|
||||
views:
|
||||
base:
|
||||
- "BackSpace"
|
||||
outlines:
|
||||
default: { width: 0, height: 0 }
|
||||
buttons:
|
||||
BackSpace:
|
||||
action: erase
|
||||
Reference in New Issue
Block a user