diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-27 15:39:37 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-27 15:42:55 +0300 |
| commit | 1f8aed673263748d9fbf61ca50d763abd221b257 (patch) | |
| tree | 8ff338704ba66940f61e13617a6007e24ef54c62 | |
| parent | fa2bace3cd0168af24c8dcd4a59db59a0017da90 (diff) | |
| download | niri-1f8aed673263748d9fbf61ca50d763abd221b257.tar.gz niri-1f8aed673263748d9fbf61ca50d763abd221b257.tar.bz2 niri-1f8aed673263748d9fbf61ca50d763abd221b257.zip | |
config: Add a test for border rule on/off merging
| -rw-r--r-- | niri-config/src/lib.rs | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 8ef4d869..d5d45650 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -2933,7 +2933,7 @@ pub fn set_miette_hook() -> Result<(), miette::InstallError> { #[cfg(test)] mod tests { - use insta::assert_debug_snapshot; + use insta::{assert_debug_snapshot, assert_snapshot}; use pretty_assertions::assert_eq; use super::*; @@ -3851,4 +3851,61 @@ mod tests { "# ); } + + #[test] + fn test_border_rule_on_off_merging() { + fn is_on(config: &str, rules: &[&str]) -> String { + let mut resolved = BorderRule { + off: false, + on: false, + width: None, + active_color: None, + inactive_color: None, + active_gradient: None, + inactive_gradient: None, + }; + + for rule in rules.iter().copied() { + let rule = BorderRule { + off: rule == "off" || rule == "off,on", + on: rule == "on" || rule == "off,on", + ..Default::default() + }; + + resolved.merge_with(&rule); + } + + let config = Border { + off: config == "off", + ..Default::default() + }; + + if resolved.resolve_against(config).off { + "off" + } else { + "on" + } + .to_owned() + } + + assert_snapshot!(is_on("off", &[]), @"off"); + assert_snapshot!(is_on("off", &["off"]), @"off"); + assert_snapshot!(is_on("off", &["on"]), @"on"); + assert_snapshot!(is_on("off", &["off,on"]), @"on"); + + assert_snapshot!(is_on("on", &[]), @"on"); + assert_snapshot!(is_on("on", &["off"]), @"off"); + assert_snapshot!(is_on("on", &["on"]), @"on"); + assert_snapshot!(is_on("on", &["off,on"]), @"on"); + + assert_snapshot!(is_on("off", &["off", "off"]), @"off"); + assert_snapshot!(is_on("off", &["off", "on"]), @"on"); + assert_snapshot!(is_on("off", &["on", "off"]), @"on"); + assert_snapshot!(is_on("off", &["on", "on"]), @"on"); + + assert_snapshot!(is_on("on", &["off", "off"]), @"off"); + assert_snapshot!(is_on("on", &["off", "on"]), @"on"); + assert_snapshot!(is_on("on", &["on", "off"]), @"on"); + assert_snapshot!(is_on("on", &["on", "on"]), @"on"); + } } |
