layout: Improve Options randomization in tests
Browse files at this commit629a2ccb47a733ef1dcc912258d7ca46928f9d32Parent: fb930381 changed file +64 -11
- src/layout/mod.rs +64 -11
src/layout/mod.rsmodified+64 -11
| @@ -33,7 +33,7 @@ use std::mem; | |||
| 33 | use std::rc::Rc; | 33 | use std::rc::Rc; |
| 34 | use std::time::Duration; | 34 | use std::time::Duration; |
| 35 | 35 | ||
| 36 | -use niri_config::{self, Config, SizeChange, Struts}; | 36 | +use niri_config::{self, CenterFocusedColumn, Config, SizeChange, Struts}; |
| 37 | use smithay::backend::renderer::element::AsRenderElements; | 37 | use smithay::backend::renderer::element::AsRenderElements; |
| 38 | use smithay::backend::renderer::{ImportAll, Renderer}; | 38 | use smithay::backend::renderer::{ImportAll, Renderer}; |
| 39 | use smithay::desktop::space::SpaceElement; | 39 | use smithay::desktop::space::SpaceElement; |
| @@ -139,7 +139,7 @@ pub struct Options { | |||
| 139 | struts: Struts, | 139 | struts: Struts, |
| 140 | focus_ring: niri_config::FocusRing, | 140 | focus_ring: niri_config::FocusRing, |
| 141 | border: niri_config::FocusRing, | 141 | border: niri_config::FocusRing, |
| 142 | - center_focused_column: niri_config::CenterFocusedColumn, | 142 | + center_focused_column: CenterFocusedColumn, |
| 143 | /// Column widths that `toggle_width()` switches between. | 143 | /// Column widths that `toggle_width()` switches between. |
| 144 | preset_widths: Vec<ColumnWidth>, | 144 | preset_widths: Vec<ColumnWidth>, |
| 145 | /// Initial width for new columns. | 145 | /// Initial width for new columns. |
| @@ -2190,8 +2190,67 @@ mod tests { | |||
| 2190 | check_ops_with_options(options, &ops); | 2190 | check_ops_with_options(options, &ops); |
| 2191 | } | 2191 | } |
| 2192 | 2192 | ||
| 2193 | - fn arbitrary_border() -> impl Strategy<Value = u16> { | 2193 | + fn arbitrary_spacing() -> impl Strategy<Value = u16> { |
| 2194 | - prop_oneof![Just(0), (1..=u16::MAX)] | 2194 | + // Give equal weight to: |
| 2195 | + // - 0: the element is disabled | ||
| 2196 | + // - 4: some reasonable value | ||
| 2197 | + // - random value, likely unreasonably big | ||
| 2198 | + prop_oneof![Just(0), Just(4), (1..=u16::MAX)] | ||
| 2199 | + } | ||
| 2200 | + | ||
| 2201 | + fn arbitrary_struts() -> impl Strategy<Value = Struts> { | ||
| 2202 | + ( | ||
| 2203 | + arbitrary_spacing(), | ||
| 2204 | + arbitrary_spacing(), | ||
| 2205 | + arbitrary_spacing(), | ||
| 2206 | + arbitrary_spacing(), | ||
| 2207 | + ) | ||
| 2208 | + .prop_map(|(left, right, top, bottom)| Struts { | ||
| 2209 | + left, | ||
| 2210 | + right, | ||
| 2211 | + top, | ||
| 2212 | + bottom, | ||
| 2213 | + }) | ||
| 2214 | + } | ||
| 2215 | + | ||
| 2216 | + fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColumn> { | ||
| 2217 | + prop_oneof![ | ||
| 2218 | + Just(CenterFocusedColumn::Never), | ||
| 2219 | + Just(CenterFocusedColumn::OnOverflow), | ||
| 2220 | + Just(CenterFocusedColumn::Always), | ||
| 2221 | + ] | ||
| 2222 | + } | ||
| 2223 | + | ||
| 2224 | + prop_compose! { | ||
| 2225 | + fn arbitrary_focus_ring()( | ||
| 2226 | + off in any::<bool>(), | ||
| 2227 | + width in arbitrary_spacing(), | ||
| 2228 | + ) -> niri_config::FocusRing { | ||
| 2229 | + niri_config::FocusRing { | ||
| 2230 | + off, | ||
| 2231 | + width, | ||
| 2232 | + ..Default::default() | ||
| 2233 | + } | ||
| 2234 | + } | ||
| 2235 | + } | ||
| 2236 | + | ||
| 2237 | + prop_compose! { | ||
| 2238 | + fn arbitrary_options()( | ||
| 2239 | + gaps in arbitrary_spacing(), | ||
| 2240 | + struts in arbitrary_struts(), | ||
| 2241 | + focus_ring in arbitrary_focus_ring(), | ||
| 2242 | + border in arbitrary_focus_ring(), | ||
| 2243 | + center_focused_column in arbitrary_center_focused_column(), | ||
| 2244 | + ) -> Options { | ||
| 2245 | + Options { | ||
| 2246 | + gaps: gaps.into(), | ||
| 2247 | + struts, | ||
| 2248 | + center_focused_column, | ||
| 2249 | + focus_ring, | ||
| 2250 | + border, | ||
| 2251 | + ..Default::default() | ||
| 2252 | + } | ||
| 2253 | + } | ||
| 2195 | } | 2254 | } |
| 2196 | 2255 | ||
| 2197 | proptest! { | 2256 | proptest! { |
| @@ -2206,13 +2265,7 @@ mod tests { | |||
| 2206 | })] | 2265 | })] |
| 2207 | 2266 | ||
| 2208 | #[test] | 2267 | #[test] |
| 2209 | - fn random_operations_dont_panic(ops: Vec<Op>, border in arbitrary_border()) { | 2268 | + fn random_operations_dont_panic(ops: Vec<Op>, options in arbitrary_options()) { |
| 2210 | - let mut options = Options::default(); | ||
| 2211 | - if border != 0 { | ||
| 2212 | - options.border.off = false; | ||
| 2213 | - options.border.width = border; | ||
| 2214 | - } | ||
| 2215 | - | ||
| 2216 | // eprintln!("{ops:?}"); | 2269 | // eprintln!("{ops:?}"); |
| 2217 | check_ops_with_options(options, &ops); | 2270 | check_ops_with_options(options, &ops); |
| 2218 | } | 2271 | } |