Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,14 @@ pub fn delocalize_input(s: &str, region: Region) -> Option<String> {
if t.is_empty() || t.starts_with(['=', '\'']) {
return None;
}
// Booleans as the Spanish and Ukrainian interfaces write them, in any case (`істина`).
// Booleans as the Spanish, Ukrainian and Czech interfaces write them, in any case (`істина`).
let booleans = match region {
Region::EsEs => Some(("VERDADERO", "FALSO")),
Region::UkUa => Some(("ІСТИНА", "ХИБНІСТЬ")),
// Czech, Romanian and Lithuanian formulas keep the English names, so TRUE and FALSE.
Region::EnUs | Region::CsCz | Region::RoRo | Region::LtLt => None,
// Czech formulas write them PRAVDA and NEPRAVDA.
Region::CsCz => Some(("PRAVDA", "NEPRAVDA")),
// Romanian and Lithuanian formulas keep the English names, so TRUE and FALSE.
Region::EnUs | Region::RoRo | Region::LtLt => None,
};
if let Some((yes, no)) = booleans {
let upper = t.to_uppercase();
Expand Down
8 changes: 6 additions & 2 deletions crates/core/tests/regional_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ fn czech_romanian_and_lithuanian_numbers_and_dates() {
assert_eq!(number("05.11.2026", ro), serial(2026, 11, 5));
assert_eq!(delocalize_input("2026-11-05", lt), None);
assert_eq!(number("2026-11-05", lt), serial(2026, 11, 5));
// Booleans stay the English names, as their formulas do.
// Czech writes the booleans PRAVDA and NEPRAVDA, as its formulas do; Romanian and
// Lithuanian keep the English names.
assert_eq!(read("TRUE", cs).0, Value::Bool(true));
assert_eq!(delocalize_input("pravda", cs), None);
assert_eq!(read("pravda", cs).0, Value::Bool(true));
assert_eq!(read("NEPRAVDA", cs).0, Value::Bool(false));
assert_eq!(delocalize_input("adevărat", ro), None);
assert_eq!(read("TRUE", lt).0, Value::Bool(true));
}
35 changes: 34 additions & 1 deletion crates/engine/tests/it/spanish_function_names.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Spanish formula entry knows every built-in function (Tinta Calculo, stage 1).
//! Localized formula entry (Spanish, Czech) knows every built-in function (Tinta Calculo).

use gridcraft_engine::cmd::formulas::function_list;
use gridcraft_engine::display::cell_text;
Expand Down Expand Up @@ -41,3 +41,36 @@ fn spanish_formulas_compute_like_english_ones() {
assert_eq!(shown, *expected, "{spanish}");
}
}

#[test]
fn every_localized_table_covers_exactly_the_listed_functions() {
let listed: Vec<String> = function_list().iter().filter_map(|f| f["name"].as_str().map(str::to_string)).collect();
for locale in FormulaLocale::ALL.into_iter().filter(|l| l.is_localized()) {
let names = locale.function_names();
let missing: Vec<&String> = listed.iter().filter(|n| !names.iter().any(|(en, _)| en == n)).collect();
let extra: Vec<&str> = names.iter().map(|p| p.0).filter(|en| !listed.iter().any(|n| n == en)).collect();
assert!(missing.is_empty() && extra.is_empty(), "{locale:?}: missing {missing:?}, unknown {extra:?}");
}
}

#[test]
fn czech_formulas_compute_like_english_ones() {
use gridcraft_engine::formula::{parse_input, print};
let mut s = gridcraft_engine::Session::new();
s.new_workbook();
let cases = [
("SUMIFS({10\\20\\30};{1\\2\\1};1)", "40"),
("ROK(DATUM(2026;11;3))", "2026"),
("ZAOKROUHLIT(PRŮMĚR(1;2;4);2)", "2.33"),
("IFERROR(1/0;\"bez dat\")", "bez dat"),
("VELKÁ(ZLEVA(\"tinta\";3))", "TIN"),
("KDYŽ(A(PRAVDA;NE(NEPRAVDA));LOG(1000);0)", "3"),
];
for (row, (czech, expected)) in cases.iter().enumerate() {
let expr = parse_input(czech, FormulaLocale::Cs, |_| false).unwrap();
s.execute("cell.set", json!({"cell": format!("A{}", row + 1), "input": format!("={}", print(&expr))})).unwrap();
let d = s.doc().unwrap();
let shown = cell_text(&d.wb, d.wb.active().unwrap(), gridcraft_engine::core::CellRef::new(row as u32, 0));
assert_eq!(shown, *expected, "{czech}");
}
}
Loading