Rename sheet-qualified defined names with their sheet (#134)

This commit is contained in:
MarekSpodBiedry 2026-10-10 19:04:13 +02:00
parent 19094e2d62
commit b19ffabdaf
2 changed files with 15 additions and 0 deletions

View File

@ -218,6 +218,13 @@ pub fn rename_sheet(e: Expr, old: &str, new: &str) -> Expr {
}
Expr::Ref(r)
}
// Sheet-qualified defined name `Old!MyName` is stored as one string.
Expr::Name(n) => match n.split_at_checked(old.len()) {
Some((head, rest)) if head.eq_ignore_ascii_case(old) && rest.starts_with('!') => {
Expr::Name(format!("{}{rest}", crate::printer::quote_sheet(new)))
}
_ => Expr::Name(n),
},
other => other,
})
}

View File

@ -163,6 +163,14 @@ fn moves_and_renames() {
assert_eq!(print(&rename_sheet(e, "Old", "New Name")), "'New Name'!A1+'New Name'!B2");
}
#[test]
fn rename_sheet_updates_qualified_names() {
let e = parse("Data!MyName+MyName+Other!MyName").unwrap();
assert_eq!(print(&rename_sheet(e, "data", "Numbers")), "Numbers!MyName+MyName+Other!MyName");
let e = parse("Data!MyName").unwrap();
assert_eq!(print(&rename_sheet(e, "Data", "New Name")), "'New Name'!MyName");
}
#[test]
fn r1c1() {
let e = parse("A1+$B$2+SUM(C:C)").unwrap();