mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-25 02:37:00 -06:00
Found while testing crates/engine/src/cmd/object.rs:299-313 (object.stroke: `st.tint = v as f32`, `st.gap_tint = v as f32`; the no-selection path at :273 clamps, this one doesn't) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
26 lines
1.2 KiB
Rust
26 lines
1.2 KiB
Rust
//! `object.stroke` keeps `tint` and `gapTint` within 0..1, so a saved document always reloads.
|
|
use designcraft_doc::ItemId;
|
|
use designcraft_engine::Session;
|
|
use serde_json::json;
|
|
|
|
fn stroked(tint: f64, gap_tint: f64) -> (Session, ItemId) {
|
|
let mut s = Session::new();
|
|
s.execute("file.new", &json!({})).unwrap();
|
|
let created = s.execute("frame.create", &json!({"rect": [36, 36, 200, 200]})).unwrap();
|
|
let id = ItemId(created["id"].as_u64().unwrap());
|
|
s.execute("object.stroke", &json!({"ids": [id.0], "swatch": "[Black]", "tint": tint, "gapTint": gap_tint})).unwrap();
|
|
(s, id)
|
|
}
|
|
|
|
#[test]
|
|
fn out_of_range_stroke_tints_are_clamped_and_the_saved_file_reloads() {
|
|
for (tint, gap, want_tint, want_gap) in [(1e300, 1e300, 1.0, 1.0), (2.0, -1.0, 1.0, 0.0), (-1e300, 0.5, 0.0, 0.5)] {
|
|
let (s, id) = stroked(tint, gap);
|
|
let doc = &s.doc().unwrap().doc;
|
|
let st = &doc.item(id).unwrap().stroke;
|
|
assert_eq!((st.tint, st.gap_tint), (want_tint, want_gap), "tint {tint}, gapTint {gap}");
|
|
let bytes = designcraft_format::save(doc).unwrap();
|
|
designcraft_format::load(&bytes).expect("reload what we just saved");
|
|
}
|
|
}
|