Re-add serde tests

pull/53/head
Takashi Kokubun 2 years ago
parent 7ab1595836
commit e8b4aed1aa
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

16
Cargo.lock generated

@ -371,6 +371,15 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "indoc"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136"
dependencies = [
"unindent",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -770,6 +779,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "unindent"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
[[package]]
name = "waker-fn"
version = "1.1.0"
@ -842,6 +857,7 @@ dependencies = [
"env_logger",
"evdev",
"getopts",
"indoc",
"lazy_static",
"log",
"nix 0.23.1",

@ -11,6 +11,7 @@ license = "MIT"
env_logger = "0.9.0"
evdev = "0.11.3"
getopts = "0.2"
indoc = "1.0"
lazy_static = "1.4.0"
log = "0.4.14"
nix = "0.23.1"

@ -7,6 +7,9 @@ pub mod key_press;
mod keymap;
mod modmap;
#[cfg(test)]
mod tests;
extern crate serde_yaml;
use keymap::Keymap;

@ -0,0 +1,109 @@
use crate::Config;
use indoc::indoc;
use serde_yaml::Error;
#[test]
fn test_modmap_basic() {
assert_parse(indoc! {"
modmap:
- name: Global
remap:
Alt_L: Ctrl_L
- remap:
Shift_R: Win_R
application:
only: Google-chrome
"})
}
#[test]
fn test_modmap_application() {
assert_parse(indoc! {"
modmap:
- remap:
Alt_L: Ctrl_L
application:
not:
- Gnome-terminal
- remap:
Shift_R: Win_R
application:
only: Google-chrome
"})
}
#[test]
fn test_modmap_multi_purpose_key() {
assert_parse(indoc! {"
modmap:
- remap:
Space:
held: Shift_L
alone: Space
- remap:
Muhenkan:
held: Alt_L
alone: Muhenkan
alone_timeout_millis: 500
"})
}
#[test]
fn test_keymap_basic() {
assert_parse(indoc! {"
keymap:
- name: Global
remap:
Alt-Enter: Ctrl-Enter
- remap:
Alt-S: Ctrl-S
"})
}
#[test]
fn test_keymap_application() {
assert_parse(indoc! {"
keymap:
- remap:
Alt-Enter: Ctrl-Enter
application:
not: Gnome-terminal
- remap:
Alt-S: Ctrl-S
application:
only:
- Gnome-terminal
"})
}
#[test]
fn test_keymap_array() {
assert_parse(indoc! {"
keymap:
- remap:
C-w:
- Shift-C-w
- C-x
"})
}
#[test]
fn test_keymap_remap() {
assert_parse(indoc! {"
keymap:
- remap:
C-x:
remap:
s: C-w
C-s:
remap:
x: C-z
"})
}
fn assert_parse(yaml: &str) {
let result: Result<Config, Error> = serde_yaml::from_str(&yaml);
if let Err(e) = result {
assert!(false, "{}", e)
}
}
Loading…
Cancel
Save