diff options
Diffstat (limited to 'alacritty_config_derive/tests/config.rs')
-rw-r--r-- | alacritty_config_derive/tests/config.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/alacritty_config_derive/tests/config.rs b/alacritty_config_derive/tests/config.rs index 4828b822..bd449ff8 100644 --- a/alacritty_config_derive/tests/config.rs +++ b/alacritty_config_derive/tests/config.rs @@ -1,8 +1,10 @@ use std::sync::{Arc, Mutex}; use log::{Level, Log, Metadata, Record}; +use serde::Deserialize; -use alacritty_config_derive::ConfigDeserialize; +use alacritty_config::SerdeReplace as _; +use alacritty_config_derive::{ConfigDeserialize, SerdeReplace}; #[derive(ConfigDeserialize, Debug, PartialEq, Eq)] enum TestEnum { @@ -63,6 +65,7 @@ struct Test2<T: Default> { field3: usize, #[config(alias = "aliased")] field4: u8, + newtype: NewType, } #[derive(ConfigDeserialize, Default)] @@ -70,6 +73,9 @@ struct Test3 { flatty: usize, } +#[derive(SerdeReplace, Deserialize, Default, PartialEq, Eq, Debug)] +struct NewType(usize); + #[test] fn config_deserialize() { let logger = unsafe { @@ -159,3 +165,33 @@ impl Log for Logger { fn flush(&self) {} } + +#[test] +fn field_replacement() { + let mut test = Test::default(); + + let value = serde_yaml::to_value(13).unwrap(); + test.replace("nesting.field2", value).unwrap(); + + assert_eq!(test.nesting.field2, Some(13)); +} + +#[test] +fn replace_derive() { + let mut test = Test::default(); + + let value = serde_yaml::to_value(9).unwrap(); + test.replace("nesting.newtype", value).unwrap(); + + assert_eq!(test.nesting.newtype, NewType(9)); +} + +#[test] +fn replace_flatten() { + let mut test = Test::default(); + + let value = serde_yaml::to_value(7).unwrap(); + test.replace("flatty", value).unwrap(); + + assert_eq!(test.flatten.flatty, 7); +} |