mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Saturate table style altRows counts instead of truncating to 32 bits
Found while testing crates/engine/src/cmd/table.rs:1742 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
d8d7885172
commit
4867a3f41b
@@ -1751,7 +1751,7 @@ fn table_style_fields(ts: &mut designcraft_doc::TableStyle, p: &Value, border: O
|
||||
ts.borders = Default::default();
|
||||
}
|
||||
if let Some(a) = p.get("altRows").and_then(Value::as_object) {
|
||||
let n = |k: &str, d: u32| a.get(k).and_then(Value::as_u64).map_or(d, |v| v as u32);
|
||||
let n = |k: &str, d: u32| a.get(k).and_then(Value::as_u64).map_or(d, |v| u32::try_from(v).unwrap_or(u32::MAX));
|
||||
let c = |k: &str| a.get(k).and_then(Value::as_str).unwrap_or(designcraft_color::swatch::NONE).to_string();
|
||||
let t = |k: &str| a.get(k).and_then(Value::as_f64).map_or(1.0, |v| v.clamp(0.0, 1.0) as f32);
|
||||
ts.alt_rows = Some(designcraft_doc::AltFills {
|
||||
@@ -2466,3 +2466,22 @@ mod resize_border_tests {
|
||||
assert!(s.execute("table.resizeBorder", &json!({"frame": f, "table": t, "axis": "column", "index": 0, "delta": 5})).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod style_alt_rows_tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::table_style_fields;
|
||||
|
||||
#[test]
|
||||
fn style_alt_rows_counts_saturate() {
|
||||
let mut ts = designcraft_doc::TableStyle::default();
|
||||
let p = json!({"altRows": {"first": 4294967297u64, "next": 4294967296u64, "skipFirst": 4294967295u64, "skipLast": 3}});
|
||||
table_style_fields(&mut ts, &p, None);
|
||||
let a = ts.alt_rows.unwrap();
|
||||
assert_eq!(a.first, u32::MAX, "first");
|
||||
assert_eq!(a.next, u32::MAX, "next");
|
||||
assert_eq!(a.skip_first, u32::MAX, "skip_first");
|
||||
assert_eq!(a.skip_last, 3, "skip_last");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user