mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-02 14:39:41 -06:00
test: pin three linked margin keys boundary and wrap merged doc comment
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
af4d1f54a7
commit
7a7be84e41
@@ -218,8 +218,8 @@ impl SlideSettings {
|
||||
|
||||
/// These settings with the keys `p` names changed (the others kept), validated and clamped.
|
||||
/// A wrong type, an unknown key or a non-finite number is an error, and nothing changes.
|
||||
/// With `linkMargins` on (already, or set in `p`), a margin given sets all four (unless all four are given); `margins`
|
||||
/// sets all four in any case.
|
||||
/// With `linkMargins` on (already, or set in `p`), a margin given sets all four (unless all four are given);
|
||||
/// `margins` sets all four in any case.
|
||||
pub fn merged(&self, p: &Value) -> Result<Self, String> {
|
||||
let Some(obj) = p.as_object() else { return Err("parameters must be an object".into()) };
|
||||
let mut s = self.clone();
|
||||
@@ -341,6 +341,14 @@ mod tests {
|
||||
assert_eq!(d.merged(&st.to_json()).unwrap(), st);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_copies_last_of_three_linked_margins() {
|
||||
let d = SlideSettings::default();
|
||||
// keys are visited in key order (bottom, left, top): the last one, `marginTop`, wins
|
||||
let s = d.merged(&json!({"marginLeft": 0.1, "marginTop": 0.3, "marginBottom": 0.2})).unwrap();
|
||||
assert_eq!((s.margin_left, s.margin_right, s.margin_top, s.margin_bottom), (0.3, 0.3, 0.3, 0.3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_validates_links_margins_and_round_trips() {
|
||||
let d = SlideSettings::default();
|
||||
|
||||
Reference in New Issue
Block a user