mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-01 10:13:09 -06:00
table.insertColumn* refuses a keepWidth that is not a bool, so a mistyped value is not taken as the default
A `"keepWidth": "false"` was read as absent and the columns shrunk as if `true` had been asked; now the command answers an error naming the field and leaves the table alone, as the other bool params that are validated do. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
76c05c1225
commit
63d1d2e588
@@ -321,7 +321,15 @@ fn with_table(s: &mut Session, p: &Value, cmd: &str, f: impl Fn(&mut Table) -> R
|
||||
|
||||
fn rows_cols(s: &mut Session, p: &Value, op: &str, name: &'static str) -> Result<Value> {
|
||||
let (r, c) = at(s, p, name)?;
|
||||
let keep_width = bool_or(p, "keepWidth", true);
|
||||
// Absent: keep the table's width; present, it must be a bool, so a mistyped value is refused
|
||||
// rather than silently taken as the default.
|
||||
let keep_width = match (op, p.get("keepWidth")) {
|
||||
(_, None) | (_, Some(Value::Null)) => true,
|
||||
(_, Some(Value::Bool(b))) => *b,
|
||||
("colLeft", Some(_)) => return Err(bad("table.insertColumnLeft", "`keepWidth` must be true or false")),
|
||||
("colRight", Some(_)) => return Err(bad("table.insertColumnRight", "`keepWidth` must be true or false")),
|
||||
_ => true,
|
||||
};
|
||||
let op = op.to_string();
|
||||
with_table(s, p, name, move |t| {
|
||||
match op.as_str() {
|
||||
|
||||
@@ -6525,6 +6525,21 @@ fn table_insert_column_keeps_the_table_width_and_copies_the_neighbour_format() {
|
||||
assert!((t.width() - 840.0 - 168.0).abs() < 1e-6, "width {}", t.width());
|
||||
}
|
||||
|
||||
/// A `keepWidth` that is not a bool is refused, naming it, and the table is left alone; it used
|
||||
/// to be read as absent and the columns shrunk as if `true` had been asked.
|
||||
#[test]
|
||||
fn table_insert_column_refuses_a_keep_width_that_is_not_a_bool() {
|
||||
let mut s = session();
|
||||
let id = table_at(&mut s, &[280.0, 280.0, 280.0], json!([["a", "b", "c"]]));
|
||||
for (cmd, bad) in [("table.insertColumnRight", json!("false")), ("table.insertColumnLeft", json!(0))] {
|
||||
let err = s.execute(cmd, &json!({"id": id.0, "col": 1, "keepWidth": bad})).unwrap_err().to_string();
|
||||
assert!(err.contains("keepWidth") && err.contains(cmd), "{err}");
|
||||
let t = table_of(&s, id);
|
||||
assert_eq!(t.n_cols(), 3, "{cmd} changed the table: {:?}", t.cols);
|
||||
assert!((t.width() - 840.0).abs() < 1e-6, "width {}", t.width());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slide_master_view_rejects_invalid_indices() {
|
||||
let mut s = Session::with_new();
|
||||
|
||||
Reference in New Issue
Block a user