layout/tests: Generate LayoutPart instead of Layout config
Browse files at this commit6aa8146c3249e38dc33b5bb6e84c04775a6bc64fParent: 4c524b41 changed file +51 -47
- src/layout/tests.rs +51 -47
src/layout/tests.rsmodified+51 -47
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use std::cell::{Cell, OnceCell, RefCell}; |
| 2 | 2 | |
| 3 | +use niri_config::utils::{Flag, MergeWith as _}; | |
| 3 | 4 | use niri_config::workspace::WorkspaceName; |
| 4 | 5 | use niri_config::{ |
| 5 | 6 | CenterFocusedColumn, FloatOrInt, OutputName, Struts, TabIndicatorLength, TabIndicatorPosition, |
| @@ -3451,10 +3452,11 @@ fn arbitrary_tab_indicator_position() -> impl Strategy<Value = TabIndicatorPosit | ||
| 3451 | 3452 | prop_compose! { |
| 3452 | 3453 | fn arbitrary_focus_ring()( |
| 3453 | 3454 | off in any::<bool>(), |
| 3454 | - width in arbitrary_spacing(), | |
| 3455 | - ) -> niri_config::FocusRing { | |
| 3456 | - niri_config::FocusRing { | |
| 3455 | + width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)), | |
| 3456 | + ) -> niri_config::BorderRule { | |
| 3457 | + niri_config::BorderRule { | |
| 3457 | 3458 | off, |
| 3459 | + on: !off, | |
| 3458 | 3460 | width, |
| 3459 | 3461 | ..Default::default() |
| 3460 | 3462 | } |
| @@ -3464,10 +3466,11 @@ prop_compose! { | ||
| 3464 | 3466 | prop_compose! { |
| 3465 | 3467 | fn arbitrary_border()( |
| 3466 | 3468 | off in any::<bool>(), |
| 3467 | - width in arbitrary_spacing(), | |
| 3468 | - ) -> niri_config::Border { | |
| 3469 | - niri_config::Border { | |
| 3469 | + width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)), | |
| 3470 | + ) -> niri_config::BorderRule { | |
| 3471 | + niri_config::BorderRule { | |
| 3470 | 3472 | off, |
| 3473 | + on: !off, | |
| 3471 | 3474 | width, |
| 3472 | 3475 | ..Default::default() |
| 3473 | 3476 | } |
| @@ -3476,12 +3479,13 @@ prop_compose! { | ||
| 3476 | 3479 | |
| 3477 | 3480 | prop_compose! { |
| 3478 | 3481 | fn arbitrary_shadow()( |
| 3479 | - on in any::<bool>(), | |
| 3480 | - width in arbitrary_spacing(), | |
| 3481 | - ) -> niri_config::Shadow { | |
| 3482 | - niri_config::Shadow { | |
| 3483 | - on, | |
| 3484 | - softness: width, | |
| 3482 | + off in any::<bool>(), | |
| 3483 | + softness in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)), | |
| 3484 | + ) -> niri_config::ShadowRule { | |
| 3485 | + niri_config::ShadowRule { | |
| 3486 | + off, | |
| 3487 | + on: !off, | |
| 3488 | + softness, | |
| 3485 | 3489 | ..Default::default() |
| 3486 | 3490 | } |
| 3487 | 3491 | } |
| @@ -3490,20 +3494,22 @@ prop_compose! { | ||
| 3490 | 3494 | prop_compose! { |
| 3491 | 3495 | fn arbitrary_tab_indicator()( |
| 3492 | 3496 | off in any::<bool>(), |
| 3493 | - hide_when_single_tab in any::<bool>(), | |
| 3494 | - place_within_column in any::<bool>(), | |
| 3495 | - width in arbitrary_spacing(), | |
| 3496 | - gap in arbitrary_spacing_neg(), | |
| 3497 | - length in (0f64..2f64), | |
| 3498 | - position in arbitrary_tab_indicator_position(), | |
| 3499 | - ) -> niri_config::TabIndicator { | |
| 3500 | - niri_config::TabIndicator { | |
| 3497 | + hide_when_single_tab in prop::option::of(any::<bool>().prop_map(Flag)), | |
| 3498 | + place_within_column in prop::option::of(any::<bool>().prop_map(Flag)), | |
| 3499 | + width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)), | |
| 3500 | + gap in prop::option::of(arbitrary_spacing_neg().prop_map(FloatOrInt)), | |
| 3501 | + length in prop::option::of((0f64..2f64) | |
| 3502 | + .prop_map(|x| TabIndicatorLength { total_proportion: Some(x) })), | |
| 3503 | + position in prop::option::of(arbitrary_tab_indicator_position()), | |
| 3504 | + ) -> niri_config::TabIndicatorPart { | |
| 3505 | + niri_config::TabIndicatorPart { | |
| 3501 | 3506 | off, |
| 3507 | + on: !off, | |
| 3502 | 3508 | hide_when_single_tab, |
| 3503 | 3509 | place_within_column, |
| 3504 | 3510 | width, |
| 3505 | 3511 | gap, |
| 3506 | - length: TabIndicatorLength { total_proportion: Some(length) }, | |
| 3512 | + length, | |
| 3507 | 3513 | position, |
| 3508 | 3514 | ..Default::default() |
| 3509 | 3515 | } |
| @@ -3511,18 +3517,18 @@ prop_compose! { | ||
| 3511 | 3517 | } |
| 3512 | 3518 | |
| 3513 | 3519 | prop_compose! { |
| 3514 | - fn arbitrary_layout_config()( | |
| 3515 | - gaps in arbitrary_spacing(), | |
| 3516 | - struts in arbitrary_struts(), | |
| 3517 | - focus_ring in arbitrary_focus_ring(), | |
| 3518 | - border in arbitrary_border(), | |
| 3519 | - shadow in arbitrary_shadow(), | |
| 3520 | - tab_indicator in arbitrary_tab_indicator(), | |
| 3521 | - center_focused_column in arbitrary_center_focused_column(), | |
| 3522 | - always_center_single_column in any::<bool>(), | |
| 3523 | - empty_workspace_above_first in any::<bool>(), | |
| 3524 | - ) -> niri_config::Layout { | |
| 3525 | - niri_config::Layout { | |
| 3520 | + fn arbitrary_layout_part()( | |
| 3521 | + gaps in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)), | |
| 3522 | + struts in prop::option::of(arbitrary_struts()), | |
| 3523 | + focus_ring in prop::option::of(arbitrary_focus_ring()), | |
| 3524 | + border in prop::option::of(arbitrary_border()), | |
| 3525 | + shadow in prop::option::of(arbitrary_shadow()), | |
| 3526 | + tab_indicator in prop::option::of(arbitrary_tab_indicator()), | |
| 3527 | + center_focused_column in prop::option::of(arbitrary_center_focused_column()), | |
| 3528 | + always_center_single_column in prop::option::of(any::<bool>().prop_map(Flag)), | |
| 3529 | + empty_workspace_above_first in prop::option::of(any::<bool>().prop_map(Flag)), | |
| 3530 | + ) -> niri_config::LayoutPart { | |
| 3531 | + niri_config::LayoutPart { | |
| 3526 | 3532 | gaps, |
| 3527 | 3533 | struts, |
| 3528 | 3534 | center_focused_column, |
| @@ -3537,17 +3543,6 @@ prop_compose! { | ||
| 3537 | 3543 | } |
| 3538 | 3544 | } |
| 3539 | 3545 | |
| 3540 | -prop_compose! { | |
| 3541 | - fn arbitrary_options()( | |
| 3542 | - layout in arbitrary_layout_config() | |
| 3543 | - ) -> Options { | |
| 3544 | - Options { | |
| 3545 | - layout, | |
| 3546 | - ..Default::default() | |
| 3547 | - } | |
| 3548 | - } | |
| 3549 | -} | |
| 3550 | - | |
| 3551 | 3546 | proptest! { |
| 3552 | 3547 | #![proptest_config(ProptestConfig { |
| 3553 | 3548 | cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() { |
| @@ -3562,13 +3557,22 @@ proptest! { | ||
| 3562 | 3557 | #[test] |
| 3563 | 3558 | fn random_operations_dont_panic( |
| 3564 | 3559 | ops: Vec<Op>, |
| 3565 | - options in arbitrary_options(), | |
| 3566 | - post_options in prop::option::of(arbitrary_options()), | |
| 3560 | + layout_config in arbitrary_layout_part(), | |
| 3561 | + post_layout_config in prop::option::of(arbitrary_layout_part()), | |
| 3567 | 3562 | ) { |
| 3568 | 3563 | // eprintln!("{ops:?}"); |
| 3564 | + let options = Options { | |
| 3565 | + layout: niri_config::Layout::from_part(&layout_config), | |
| 3566 | + ..Default::default() | |
| 3567 | + }; | |
| 3568 | + | |
| 3569 | 3569 | let mut layout = check_ops_with_options(options, ops); |
| 3570 | 3570 | |
| 3571 | - if let Some(post_options) = post_options { | |
| 3571 | + if let Some(layout_config) = post_layout_config { | |
| 3572 | + let post_options = Options { | |
| 3573 | + layout: niri_config::Layout::from_part(&layout_config), | |
| 3574 | + ..Default::default() | |
| 3575 | + }; | |
| 3572 | 3576 | layout.update_options(post_options); |
| 3573 | 3577 | layout.verify_invariants(); |
| 3574 | 3578 | } |