Files
cadcraft/crates/engine/tests/measureinit.rs
T
fde62a39ab MEASUREINIT: choose the units of new drawings, kept in the profile (#1792)
* MEASUREINIT: choose the units of new drawings, kept in the profile

NEW, QNEW and the first drawing at startup were always imperial unless a
template or {"metric": true} was given, and nothing kept a metric choice
across restarts. MEASUREINIT (0 imperial, the default; 1 metric) is now a
profile variable: NEW without `metric` or a template follows it, the app's
startup drawing follows it, and Options > Files shows it as "Units of new
drawings". QNEWTEMPLATE and an explicit `metric` still win.

Part of #1182.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxn7PD9WzP4ET2LU7BRLDK

* contributors: add Richard Sauer (aussieboer61)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxn7PD9WzP4ET2LU7BRLDK

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
2026-10-24 01:54:51 -04:00

52 lines
1.8 KiB
Rust

//! MEASUREINIT: the units of a new drawing made without a template (issue #1182). It is a profile
//! setting, so a metric choice survives restarts; an explicit `metric` or template still wins.
use cadcraft_engine::Session;
use serde_json::json;
fn var(s: &mut Session, name: &str) -> serde_json::Value {
s.execute("getvar", &json!({ "name": name })).unwrap()["value"].clone()
}
#[test]
fn imperial_by_default() {
let mut s = Session::empty();
assert_eq!(var(&mut s, "MEASUREINIT"), json!(0));
s.execute("new", &json!({})).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(1));
assert_eq!(var(&mut s, "MEASUREMENT"), json!(0));
}
#[test]
fn new_follows_measureinit() {
let mut s = Session::empty();
s.execute("options", &json!({ "MEASUREINIT": 1 })).unwrap();
s.execute("new", &json!({})).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(4));
assert_eq!(var(&mut s, "MEASUREMENT"), json!(1));
assert_eq!(var(&mut s, "DIMSTYLE"), json!("ISO-25"));
// An explicit choice still wins.
s.execute("new", &json!({ "metric": false })).unwrap();
assert_eq!(var(&mut s, "INSUNITS"), json!(1));
}
#[test]
fn only_zero_or_one() {
let mut s = Session::empty();
for bad in [json!(2), json!(-1), json!("metric")] {
assert!(s.execute("options", &json!({ "MEASUREINIT": bad })).is_err(), "{bad}");
}
assert_eq!(var(&mut s, "MEASUREINIT"), json!(0));
}
#[test]
fn kept_in_the_profile() {
let mut s = Session::empty();
s.execute("options", &json!({ "MEASUREINIT": 1 })).unwrap();
let saved = cadcraft_engine::cmd::options::profile(&s);
assert_eq!(saved["MEASUREINIT"], json!(1));
let mut restarted = Session::empty();
cadcraft_engine::cmd::options::restore(&mut restarted, &saved);
assert_eq!(var(&mut restarted, "MEASUREINIT"), json!(1));
}