config: Add a test for border rule on/off merging
Browse files at this commit1f8aed673263748d9fbf61ca50d763abd221b257Parent: fa2bace1 changed file +58 -1
- niri-config/src/lib.rs +58 -1
niri-config/src/lib.rsmodified+58 -1
| @@ -2933,7 +2933,7 @@ pub fn set_miette_hook() -> Result<(), miette::InstallError> { | |||
| 2933 | 2933 | ||
| 2934 | #[cfg(test)] | 2934 | #[cfg(test)] |
| 2935 | mod tests { | 2935 | mod tests { |
| 2936 | - use insta::assert_debug_snapshot; | 2936 | + use insta::{assert_debug_snapshot, assert_snapshot}; |
| 2937 | use pretty_assertions::assert_eq; | 2937 | use pretty_assertions::assert_eq; |
| 2938 | 2938 | ||
| 2939 | use super::*; | 2939 | use super::*; |
| @@ -3851,4 +3851,61 @@ mod tests { | |||
| 3851 | "# | 3851 | "# |
| 3852 | ); | 3852 | ); |
| 3853 | } | 3853 | } |
| 3854 | + | ||
| 3855 | + #[test] | ||
| 3856 | + fn test_border_rule_on_off_merging() { | ||
| 3857 | + fn is_on(config: &str, rules: &[&str]) -> String { | ||
| 3858 | + let mut resolved = BorderRule { | ||
| 3859 | + off: false, | ||
| 3860 | + on: false, | ||
| 3861 | + width: None, | ||
| 3862 | + active_color: None, | ||
| 3863 | + inactive_color: None, | ||
| 3864 | + active_gradient: None, | ||
| 3865 | + inactive_gradient: None, | ||
| 3866 | + }; | ||
| 3867 | + | ||
| 3868 | + for rule in rules.iter().copied() { | ||
| 3869 | + let rule = BorderRule { | ||
| 3870 | + off: rule == "off" || rule == "off,on", | ||
| 3871 | + on: rule == "on" || rule == "off,on", | ||
| 3872 | + ..Default::default() | ||
| 3873 | + }; | ||
| 3874 | + | ||
| 3875 | + resolved.merge_with(&rule); | ||
| 3876 | + } | ||
| 3877 | + | ||
| 3878 | + let config = Border { | ||
| 3879 | + off: config == "off", | ||
| 3880 | + ..Default::default() | ||
| 3881 | + }; | ||
| 3882 | + | ||
| 3883 | + if resolved.resolve_against(config).off { | ||
| 3884 | + "off" | ||
| 3885 | + } else { | ||
| 3886 | + "on" | ||
| 3887 | + } | ||
| 3888 | + .to_owned() | ||
| 3889 | + } | ||
| 3890 | + | ||
| 3891 | + assert_snapshot!(is_on("off", &[]), @"off"); | ||
| 3892 | + assert_snapshot!(is_on("off", &["off"]), @"off"); | ||
| 3893 | + assert_snapshot!(is_on("off", &["on"]), @"on"); | ||
| 3894 | + assert_snapshot!(is_on("off", &["off,on"]), @"on"); | ||
| 3895 | + | ||
| 3896 | + assert_snapshot!(is_on("on", &[]), @"on"); | ||
| 3897 | + assert_snapshot!(is_on("on", &["off"]), @"off"); | ||
| 3898 | + assert_snapshot!(is_on("on", &["on"]), @"on"); | ||
| 3899 | + assert_snapshot!(is_on("on", &["off,on"]), @"on"); | ||
| 3900 | + | ||
| 3901 | + assert_snapshot!(is_on("off", &["off", "off"]), @"off"); | ||
| 3902 | + assert_snapshot!(is_on("off", &["off", "on"]), @"on"); | ||
| 3903 | + assert_snapshot!(is_on("off", &["on", "off"]), @"on"); | ||
| 3904 | + assert_snapshot!(is_on("off", &["on", "on"]), @"on"); | ||
| 3905 | + | ||
| 3906 | + assert_snapshot!(is_on("on", &["off", "off"]), @"off"); | ||
| 3907 | + assert_snapshot!(is_on("on", &["off", "on"]), @"on"); | ||
| 3908 | + assert_snapshot!(is_on("on", &["on", "off"]), @"on"); | ||
| 3909 | + assert_snapshot!(is_on("on", &["on", "on"]), @"on"); | ||
| 3910 | + } | ||
| 3854 | } | 3911 | } |