use crate::reference::CellRef;
use crate::traits::FunctionContext;
use formualizer_parse::parser::ReferenceType;
#[cfg(test)]
mod tests {
use super::*;
struct DefaultContext;
impl<'ctx> FunctionContext<'ctx> for DefaultContext {
fn locale(&self) -> crate::locale::Locale {
crate::locale::Locale::invariant()
}
fn current_sheet(&self) -> &str {
"Sheet"
}
fn timezone(&self) -> &crate::timezone::TimeZoneSpec {
&crate::timezone::TimeZoneSpec::Utc
}
fn clock(&self) -> &dyn crate::timezone::ClockProvider {
static CLOCK: std::sync::OnceLock<crate::timezone::SystemClock> =
std::sync::OnceLock::new();
CLOCK.get_or_init(|| {
crate::timezone::SystemClock::new(crate::timezone::TimeZoneSpec::Utc)
})
}
fn thread_pool(&self) -> Option<&std::sync::Arc<rayon::ThreadPool>> {
None
}
fn cancellation_token(&self) -> Option<std::sync::Arc<std::sync::atomic::AtomicBool>> {
None
}
fn chunk_hint(&self) -> Option<usize> {
None
}
fn volatile_level(&self) -> crate::traits::VolatileLevel {
crate::traits::VolatileLevel::Always
}
fn workbook_seed(&self) -> u64 {
0
}
fn recalc_epoch(&self) -> u64 {
0
}
fn current_cell(&self) -> Option<CellRef> {
None
}
fn resolve_range_view(
&self,
_reference: &ReferenceType,
_current_sheet: &str,
) -> Result<crate::engine::range_view::RangeView<'ctx>, formualizer_common::ExcelError>
{
Err(formualizer_common::ExcelError::new(
formualizer_common::ExcelErrorKind::NImpl,
))
}
}
#[test]
fn test_get_or_flatten_returns_none_by_default() {
let ctx = DefaultContext;
let cell_ref = ReferenceType::cell(Some("Sheet1".to_string()), 1, 1);
let range_ref = ReferenceType::range(
Some("Sheet1".to_string()),
Some(1),
Some(1),
Some(10),
Some(5),
);
}
#[test]
fn test_hooks_do_not_affect_existing_behavior() {
let ctx = DefaultContext;
fn accepts_context(_ctx: &dyn FunctionContext<'_>) {
}
accepts_context(&ctx);
for _ in 0..10 {
let cell_ref = ReferenceType::cell(None, 1, 1);
}
}
}