use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::params::{getsparam, setsparam};
pub fn _expand_word() -> i32 {
let saved = getsparam("curcontext").unwrap_or_default();
let new_ctx = if saved.is_empty() {
"expand-word:::".to_string()
} else {
let tail = saved.splitn(2, ':').nth(1).unwrap_or("");
format!("expand-word:{}", tail)
};
let _ = setsparam("curcontext", &new_ctx);
let r =
dispatch_function_call("_main_complete", &["_expand".to_string()]).unwrap_or(1);
let _ = setsparam("curcontext", &saved);
r
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_one_without_executor() {
let _g = crate::test_util::global_state_lock();
assert_eq!(_expand_word(), 1);
}
#[test]
fn restores_curcontext_after_call() {
let _g = crate::test_util::global_state_lock();
let _ = setsparam("curcontext", "original:ctx:foo:bar");
let _ = _expand_word();
assert_eq!(getsparam("curcontext").as_deref(), Some("original:ctx:foo:bar"));
}
}