From eb903bccc5a5bd14c021f915a9a71ac23ab4f702 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 21:08:37 -0700 Subject: [PATCH] refactor(mac): converge core/animation.rs and animation/prefix.rs to the shared version core/animation.rs takes the shared copy (module docs, three serde unit tests) and its one doc comment now reads 'Bezier' like the Windows copy; that text is the description of the CubicBezier branch in schema.json, so schema.json changes in that one line (description only; the Windows schema keeps its text). prefix.rs gets the module docs; the macOS-only AnimationPrefix (no Transparency) is converged in the next revision. Verified: fast-check macOS (fake CC) cargo check --workspace --all-targets: PASS. jj diff of schema.json: the single description line. macOS tests not run (cannot). --- .../komorebi/src/animation/prefix.rs | 2 + .../komorebi/src/core/animation.rs | 43 ++++++++++++++++++- komorebi-for-mac/schema.json | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/komorebi-for-mac/komorebi/src/animation/prefix.rs b/komorebi-for-mac/komorebi/src/animation/prefix.rs index c8d26ace..23dcf0bc 100644 --- a/komorebi-for-mac/komorebi/src/animation/prefix.rs +++ b/komorebi-for-mac/komorebi/src/animation/prefix.rs @@ -1,3 +1,5 @@ +//! The kinds of animation that settings can be given for, by prefix (`movement`). + use clap::ValueEnum; use serde::Deserialize; diff --git a/komorebi-for-mac/komorebi/src/core/animation.rs b/komorebi-for-mac/komorebi/src/core/animation.rs index 659685a7..02be31f7 100644 --- a/komorebi-for-mac/komorebi/src/core/animation.rs +++ b/komorebi-for-mac/komorebi/src/core/animation.rs @@ -1,3 +1,5 @@ +//! The easing curves an animation can have (`komorebic animation-style`). + use clap::ValueEnum; use serde::Deserialize; @@ -74,7 +76,7 @@ pub enum AnimationStyle { EaseInOutBounce, #[cfg_attr(feature = "schemars", schemars(title = "CubicBezier"))] #[value(skip)] - /// Custom Cubic Bézier function + /// Custom Cubic Bezier function CubicBezier(f64, f64, f64, f64), } @@ -152,3 +154,42 @@ impl Serialize for AnimationStyle { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_style_is_written_as_its_name_and_a_bezier_as_four_numbers() { + assert_eq!( + serde_json::to_string(&AnimationStyle::EaseInOutSine).unwrap(), + r#""EaseInOutSine""# + ); + assert_eq!( + serde_json::to_string(&AnimationStyle::CubicBezier(0.32, 0.72, 0.0, 1.0)).unwrap(), + "[0.32,0.72,0.0,1.0]" + ); + } + + #[test] + fn a_style_is_read_back_from_what_it_is_written_as() { + for style in [ + AnimationStyle::Linear, + AnimationStyle::EaseOutBounce, + AnimationStyle::CubicBezier(0.1, 0.2, 0.3, 0.4), + ] { + let json = serde_json::to_string(&style).unwrap(); + assert_eq!( + serde_json::from_str::(&json).unwrap(), + style + ); + } + } + + #[test] + fn a_name_that_is_no_style_and_a_bezier_that_is_not_four_numbers_are_refused() { + assert!(serde_json::from_str::(r#""EaseInPlace""#).is_err()); + assert!(serde_json::from_str::("[0.1, 0.2, 0.3]").is_err()); + assert!(serde_json::from_str::("[0.1, 0.2, 0.3, 0.4, 0.5]").is_err()); + } +} diff --git a/komorebi-for-mac/schema.json b/komorebi-for-mac/schema.json index fbbffc56..f6a07c48 100644 --- a/komorebi-for-mac/schema.json +++ b/komorebi-for-mac/schema.json @@ -511,7 +511,7 @@ }, { "title": "CubicBezier", - "description": "Custom Cubic Bézier function", + "description": "Custom Cubic Bezier function", "type": "object", "properties": { "CubicBezier": {