mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-25 02:47:02 -06:00
Refuse to create a variable collection with a name that is already taken (#416)
This commit is contained in:
@@ -112,6 +112,9 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
spec!("variable.createCollection", "Create variable collection", "{name, modes? [names]}", true, |s, p| {
|
||||
let name = req_string("variable.createCollection", p, "name")?;
|
||||
let doc = s.doc_mut()?;
|
||||
if doc.variables.collections.iter().any(|c| c.name == name) {
|
||||
return Err(bad("variable.createCollection", format!("a collection named `{name}` already exists")));
|
||||
}
|
||||
let id = doc.new_collection_id();
|
||||
let modes: Vec<String> = match get(p, "modes") {
|
||||
Some(Value::Array(a)) => a.iter().filter_map(|m| m.as_str().map(str::to_string)).collect(),
|
||||
|
||||
@@ -114,3 +114,14 @@ fn field_scopes_by_property_and_layer() {
|
||||
assert_eq!(scope(f, "paddingHorizontal"), Some("GAP"));
|
||||
assert_eq!(scope(f, "visible"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_collection_refuses_a_taken_name() {
|
||||
let mut s = Session::new();
|
||||
ex(&mut s, "variable.createCollection", json!({"name": "Theme"}));
|
||||
let before = s.doc().unwrap().variables.collections.len();
|
||||
assert!(s.execute("variable.createCollection", &json!({"name": "Theme"})).is_err());
|
||||
assert_eq!(s.doc().unwrap().variables.collections.len(), before);
|
||||
ex(&mut s, "variable.createCollection", json!({"name": "Theme 2"}));
|
||||
assert_eq!(s.doc().unwrap().variables.collections.len(), before + 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user