mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 12:24:54 +00:00
fix(engine): preset imports number duplicate names in linear time
This commit is contained in:
committed by
bflatastic
parent
706c8f850e
commit
891e90bfee
@@ -66,6 +66,28 @@ fn unique_name_appends_the_first_free_number() {
|
||||
assert_eq!(unique_name("A 2", |n| taken.contains(&n)), "A 2 2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unique_name_from_counts_on_for_a_run_of_one_name() {
|
||||
let mut taken = vec!["A".to_string(), "a 3".to_string()];
|
||||
let mut next = std::collections::HashMap::new();
|
||||
for want in ["A 2", "A 4", "A 5"] {
|
||||
let is_taken = |n: &str| taken.iter().any(|t| t.eq_ignore_ascii_case(n));
|
||||
let n = crate::cmd::unique_name_from("A", &mut next, is_taken);
|
||||
assert_eq!(n, want);
|
||||
taken.push(n);
|
||||
}
|
||||
assert_eq!(crate::cmd::unique_name_from("B", &mut next, |_| false), "B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_presets_file_with_too_many_presets_is_refused() {
|
||||
let mut s = Session::new();
|
||||
let presets: Vec<_> = (0..=crate::cmd::MAX_IMPORTED_PRESETS).map(|_| serde_json::json!({"name": "P"})).collect();
|
||||
let file = serde_json::json!({"format": crate::cmd::printpresets::PRESET_FORMAT, "presets": presets}).to_string();
|
||||
let e = s.execute("print.presets.import", &serde_json::json!({"data": file})).unwrap_err().to_string();
|
||||
assert!(e.contains("over"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaf_targets_expand_groups_and_stop_at_compound_paths() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user