added shared data field and tests

pull/402/head
Pieter 5 months ago
parent f1064620aa
commit 43e15fe1ed
No known key found for this signature in database
GPG Key ID: C44AEAD55BC105EB

@ -17,7 +17,7 @@ use evdev::Key;
use keymap::Keymap;
use modmap::Modmap;
use nix::sys::inotify::{AddWatchFlags, InitFlags, Inotify};
use serde::{Deserialize, Deserializer};
use serde::{Deserialize, Deserializer, de::IgnoredAny};
use std::{collections::HashMap, error, fs, path::PathBuf, time::SystemTime};
use self::{
@ -40,6 +40,11 @@ pub struct Config {
#[serde(default)]
pub keypress_delay_ms: u64,
// Data is not used by any part of the application.
// but can be used with Anchors and Aliases
#[serde(default)]
pub shared: IgnoredAny,
// Internals
#[serde(skip)]
pub modify_time: Option<SystemTime>,

@ -209,6 +209,46 @@ fn test_keymap_mark() {
"})
}
#[test]
fn test_shared_data_anchor() {
assert_parse(indoc! {"
shared:
terminals: &terminals
- Gnome-terminal
- Kitty
modmap:
- remap:
Alt_L: Ctrl_L
application:
not: *terminals
- remap:
Shift_R: Win_R
application:
only: Google-chrome
"})
}
#[test]
#[should_panic]
fn test_fail_on_data_outside_of_config_model() {
assert_parse(indoc! {"
terminals: &terminals
- Gnome-terminal
- Kitty
modmap:
- remap:
Alt_L: Ctrl_L
application:
not: *terminals
- remap:
Shift_R: Win_R
application:
only: Google-chrome
"})
}
fn assert_parse(yaml: &str) {
let result: Result<Config, Error> = serde_yaml::from_str(yaml);
if let Err(e) = result {

Loading…
Cancel
Save