ARRAY counts: test ARRAYEDIT's counts and the MAXARRAY bounds

ARRAYEDIT's columns, rows and items, measured in AutoCAD 2024's core
console, refuse 5.0, 5., 4.5, 1e1 and 8/2 and take +5, 05 and 5, as the
other count prompts do. A count runs from 1 to the MAXARRAY limit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2ez4gcx
2026-11-20 21:19:36 +07:00
co-authored by Claude Opus 5.5
parent c40fc740ab
commit b781f04784
+68 -3
View File
@@ -1,10 +1,10 @@
//! The counts the ARRAY commands ask for take a whole number as typed, as AutoCAD 2024's do
//! (measured in its core console at ARRAYRECT's rows and columns, ARRAYPOLAR's items and rows,
//! and -ARRAY's rows and items): +3 and 03 are three, and 5.0, 1e1, 8/2 and 3' are refused and
//! asked for again.
//! -ARRAY's rows and items, and ARRAYEDIT's columns, rows and items): +3 and 03 are three, and
//! 5.0, 1e1 and 8/2 are refused and asked for again, as 3' is where it was typed (all but ARRAYEDIT).
use cadcraft_engine::Session;
use cadcraft_engine::doc::EntityKind;
use cadcraft_engine::doc::{ArrayKind, EntityKind, Handle};
use serde_json::json;
/// Texts AutoCAD 2024 refuses at an array count.
@@ -50,6 +50,33 @@ fn arrayrect_columns_and_rows() {
assert_eq!(lines(&s), 9);
}
/// The bounds are CADCraft's, which this rule leaves as they were: a count runs from 1 to what
/// MAXARRAY allows for the array's other counts. With MAXARRAY 100 and three rows, 0 and 34 columns
/// are refused and 33 taken; then 4 rows are refused and 3 taken.
#[test]
fn a_count_runs_from_one_to_the_maxarray_limit() {
let mut s = with_line();
s.execute("setvar", &json!({ "name": "MAXARRAY", "value": 100 })).unwrap();
typed(&mut s, &["arrayrect", "l", "", "cou"]);
let refused = |s: &mut Session, texts: &[&str], max: u64| {
let asked = s.prompt_text();
for t in texts {
s.cmdline(t).unwrap();
let msg = format!("Requires an integer between 1 and {max} ");
assert!(s.log.last().is_some_and(|l| l.starts_with(&msg)), "{t}: {:?}", s.log.last());
assert_eq!(s.prompt_text(), asked, "{t}");
}
};
assert!(s.prompt_text().contains("Enter the number of columns"), "{}", s.prompt_text());
refused(&mut s, &["0", "34"], 33);
s.cmdline("33").unwrap();
assert!(s.prompt_text().contains("Enter the number of rows"), "{}", s.prompt_text());
refused(&mut s, &["0", "4"], 3);
typed(&mut s, &["3", "as", "n", "x"]);
assert!(s.current_prompt().is_none(), "{}", s.prompt_text());
assert_eq!(lines(&s), 99);
}
#[test]
fn arraypolar_items() {
let mut s = with_line();
@@ -61,6 +88,44 @@ fn arraypolar_items() {
assert_eq!(lines(&s), 5);
}
/// ARRAYEDIT's counts follow the same rule: AutoCAD 2024 refuses 5.0, 5., 4.5, 1e1 and 8/2 at a
/// rectangular array's columns and rows and a polar array's items, and takes +5, 05 and 5.
#[test]
fn arrayedit_counts() {
let refused = ["5.0", "5.", "4.5", "1e1", "8/2"];
let edit = |s: &mut Session, h: Handle, option: &str, asked: &str, count: &str, after: &[&str]| {
s.set_selection(vec![h]);
typed(s, &["arrayedit", option]);
assert!(s.prompt_text().contains(asked), "{}", s.prompt_text());
let prompt = s.prompt_text();
for t in refused {
s.cmdline(t).unwrap();
assert!(s.log.last().is_some_and(|l| l.starts_with("Requires an integer between 1 and")), "{t}: {:?}", s.log.last());
assert_eq!(s.prompt_text(), prompt, "{t}");
}
s.cmdline(count).unwrap();
typed(s, after);
assert!(s.current_prompt().is_none(), "{}", s.prompt_text());
let d = s.doc().unwrap();
d.array_params(d.entity(h).unwrap()).unwrap().kind
};
let mut s = with_line();
let l = s.doc().unwrap().model.iter().next().unwrap().handle.hex();
let r = s.execute("arrayrect", &json!({ "handles": [l], "cols": 4, "rows": 3, "colSpacing": 5, "rowSpacing": 5 })).unwrap();
let h = Handle::parse_hex(r["handle"].as_str().unwrap()).unwrap();
let ArrayKind::Rect(a) = edit(&mut s, h, "col", "Enter the number of columns", "+5", &["", "x"]) else { panic!("not rectangular") };
assert_eq!((a.cols, a.rows), (5, 3));
let ArrayKind::Rect(a) = edit(&mut s, h, "r", "Enter the number of rows", "05", &["", "", "x"]) else { panic!("not rectangular") };
assert_eq!((a.cols, a.rows), (5, 5));
let mut s = with_line();
let l = s.doc().unwrap().model.iter().next().unwrap().handle.hex();
let r = s.execute("arraypolar", &json!({ "handles": [l], "center": [0, -50], "count": 6 })).unwrap();
let h = Handle::parse_hex(r["handle"].as_str().unwrap()).unwrap();
let ArrayKind::Polar(a) = edit(&mut s, h, "i", "Enter number of items in array", "5", &["x"]) else { panic!("not polar") };
assert_eq!(a.items, 5);
}
#[test]
fn classic_array_rows_columns_and_items() {
let mut s = with_line();