From 8999168956026c21dd08d2e89a46fa2f848f0649 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Mon, 30 Nov 2026 17:02:48 +0000 Subject: [PATCH 1/2] eval: inline array constants work like ranges; MATCH/INDEX fixes; showcase - src/arrays.rs: for standalone evaluation (CLI eval, MCP/API eval, Ask preview) each {..} constant is written to scratch cells and the formula points at that range, so IRR({..}), COUNTIF, ROWS, AVERAGEIFS, SUMPRODUCT ({1,2,3},{4,5,6}) = 32 etc. behave as in Excel. Workbook cells untouched. - patches/0002: engine MATCH type 1 returns the largest value <= lookup (was first >=, so MATCH(25,{10,20,30},1) gave 3); INDEX(row, n) on a single-row range picks the column, as in Excel. - Homepage: 56 examples in 9 groups as click-to-run chips, an Ask AI box (c0mpute) on the page, a fuller default demo. A test evaluates every example against the real engine so a broken one cannot ship. Co-Authored-By: Claude Opus 5.5 --- cloud/src/page.ts | 115 +++++++++++- cloud/test/app.test.ts | 14 +- .../0002-match-index-excel-semantics.patch | 66 +++++++ src/arrays.rs | 174 ++++++++++++++++++ src/cli.rs | 9 +- src/main.rs | 1 + src/mcp.rs | 8 +- 7 files changed, 364 insertions(+), 23 deletions(-) create mode 100644 patches/0002-match-index-excel-semantics.patch create mode 100644 src/arrays.rs diff --git a/cloud/src/page.ts b/cloud/src/page.ts index 5b90405..62a4b03 100644 --- a/cloud/src/page.ts +++ b/cloud/src/page.ts @@ -47,6 +47,11 @@ section h2{font-size:26px;margin:0 0 6px}section .sub{color:var(--dim);margin:0 .demo table{width:100%;border-collapse:collapse;margin-top:14px;font:14px ui-monospace,Menlo,monospace} .demo td{border-top:1px solid var(--line);padding:6px 8px;vertical-align:top;word-break:break-word}.demo td.v{color:var(--accent);text-align:right} .note{color:var(--dim);font-size:14px}.err{color:var(--err)} +.ask{display:flex;gap:10px;margin:6px 0 4px;flex-wrap:wrap}.ask input{flex:1;min-width:min(100%,260px)} +.gallery{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,300px),1fr));gap:14px;margin-top:22px} +.ex h3{margin:0 0 8px;font-size:15px;color:var(--dim);font-weight:600}.chips{display:flex;flex-wrap:wrap;gap:6px} +.chip{background:var(--panel);color:var(--fg);border:1px solid var(--line);font:500 13px system-ui,sans-serif;padding:5px 10px;border-radius:999px} +.chip:hover{border-color:var(--accent);color:var(--accent)} .price{display:flex;flex-direction:column;gap:10px} .price .amt{font:700 32px system-ui,sans-serif}.price .amt small{font-size:15px;color:var(--dim);font-weight:500} .price ul{margin:0;padding-left:18px;color:var(--dim)}.price .btn{margin-top:auto;text-align:center} @@ -89,6 +94,91 @@ const TERM = `
 sk33p  budget.
    4 │ total        │              │       156.00
  READY                                   ? help  ^S save  ^Q quit
` +/** + * The showcase. Every formula here is evaluated in test/app.test.ts against the real + * engine and must not return an error, so a broken example cannot ship. + * Lists written with ; are columns (what SORT/UNIQUE/TAKE expect, as in Excel). + */ +export const EXAMPLES: { group: string; items: [formula: string, label: string][] }[] = [ + { group: 'Finance', items: [ + ['=ROUND(PMT(6%/12,360,-300000),2)', 'mortgage payment'], + ['=ROUND(FV(5%/12,120,-200),2)', '$200/month for 10 years'], + ['=ROUND(IRR({-1000;300;400;500}),4)', 'IRR of cash flows'], + ['=ROUND(NPV(8%,300,400,500)-1000,2)', 'net present value'], + ['=ROUND(RATE(36,-300,10000)*12,4)', 'loan APR'], + ['=ROUND(NPER(5%/12,-500,20000),1)', 'months to pay off'], + ['=ROUND(EFFECT(6%,12),5)', 'effective annual rate'], + ['=ROUND(DB(30000,5000,5,1),2)', 'depreciation'], + ] }, + { group: 'Lookup', items: [ + ['=XLOOKUP("gold",{"bronze";"silver";"gold"},{10;20;50})', 'XLOOKUP'], + ['=VLOOKUP(2,{1,"apple";2,"banana";3,"cherry"},2,FALSE)', 'VLOOKUP'], + ['=HLOOKUP("Q2",{"Q1","Q2","Q3";120,145,160},2,FALSE)', 'HLOOKUP'], + ['=INDEX({"F";"C";"B";"A"},MATCH(84,{0;60;80;90},1))', 'grade from score'], + ] }, + { group: 'Dynamic arrays', items: [ + ['=TEXTJOIN(", ",TRUE,SORT({"pear";"apple";"fig"}))', 'SORT'], + ['=TEXTJOIN(", ",TRUE,UNIQUE({"a";"b";"a";"c";"b"}))', 'UNIQUE'], + ['=TEXTJOIN(", ",TRUE,FILTER({12;45;7;88;30},{12;45;7;88;30}>25))', 'FILTER'], + ['=TEXTJOIN(", ",TRUE,SORTBY({"x";"y";"z"},{3;1;2}))', 'SORTBY'], + ['=TEXTJOIN(", ",TRUE,SEQUENCE(5,1,0,25))', 'SEQUENCE'], + ['=TEXTJOIN(", ",TRUE,TAKE(SORT({4;9;1;7;3},1,-1),3))', 'top 3'], + ] }, + { group: 'LET and LAMBDA', items: [ + ['=LET(rate,6%/12,n,360,loan,300000,ROUND(PMT(rate,n,-loan),2))', 'LET'], + ['=SUM(MAP({1;2;3;4},LAMBDA(x,x*x)))', 'MAP'], + ['=REDUCE(1,{1;2;3;4;5},LAMBDA(acc,x,acc*x))', 'REDUCE (5!)'], + ['=TEXTJOIN(", ",TRUE,BYROW({1,2;3,4;5,6},LAMBDA(r,SUM(r))))', 'BYROW'], + ['=LAMBDA(c,ROUND(c*9/5+32,1))(37)', 'inline LAMBDA'], + ] }, + { group: 'Text', items: [ + ['=TEXTBEFORE("jane.doe@example.com","@")', 'TEXTBEFORE'], + ['=TEXTAFTER("jane.doe@example.com","@")', 'TEXTAFTER'], + ['=PROPER("the quick brown fox")', 'PROPER'], + ['=TEXT(1234567.891,"#,##0.00")', 'number format'], + ['=TEXT(0.256,"0.0%")', 'percent format'], + ['=REGEXEXTRACT("order #4821 shipped","[0-9]+")', 'REGEXEXTRACT'], + ['=TEXTJOIN(" | ",TRUE,TEXTSPLIT("red,green,blue",","))', 'TEXTSPLIT'], + ] }, + { group: 'Dates', items: [ + ['=TEXT(DATE(2026,11,30),"dddd, mmmm d, yyyy")', 'date format'], + ['=NETWORKDAYS(DATE(2026,12,1),DATE(2026,12,31))', 'working days'], + ['=TEXT(EOMONTH(DATE(2026,2,10),0),"yyyy-mm-dd")', 'end of month'], + ['=TEXT(EDATE(DATE(2026,1,31),1),"yyyy-mm-dd")', 'add a month'], + ['=DATEDIF(DATE(1990,6,15),DATE(2026,11,30),"Y")', 'age in years'], + ] }, + { group: 'Statistics', items: [ + ['=MEDIAN({3;8;1;9;4})', 'MEDIAN'], + ['=ROUND(STDEV({2;4;4;4;5;5;7;9}),4)', 'STDEV'], + ['=ROUND(CORREL({1;2;3;4},{2;4;5;8}),4)', 'CORREL'], + ['=COUNTIF({"yes";"no";"yes";"yes"},"yes")', 'COUNTIF'], + ['=AVERAGEIFS({10;20;30;40},{"a";"b";"a";"b"},"a")', 'AVERAGEIFS'], + ['=SUMPRODUCT({2;3;5},{10;20;30})', 'SUMPRODUCT'], + ] }, + { group: 'Logic', items: [ + ['=IFS(84>=90,"A",84>=80,"B",TRUE,"C")', 'IFS'], + ['=SWITCH(WEEKDAY(DATE(2026,11,30)),1,"Sun",2,"Mon",3,"Tue","later")', 'SWITCH'], + ['=IFERROR(1/0,"divide by zero caught")', 'IFERROR'], + ] }, + { group: 'Math and engineering', items: [ + ['=POWER(2,10)', 'powers (no ^)'], + ['=GCD(48,180)', 'GCD'], + ['=DEC2HEX(48879)', 'hex'], + ['=BIN2DEC("101010")', 'binary'], + ['=ROMAN(2026)', 'roman numerals'], + ['=BASE(255,2)', 'any base'], + ] }, +] + +const DEMO_DEFAULT = [ + '=ROUND(PMT(6%/12,360,-300000),2)', + '=XLOOKUP("gold",{"bronze";"silver";"gold"},{10;20;50})', + '=TEXTJOIN(", ",TRUE,SORT({"pear";"apple";"fig"}))', + '=LET(rate,6%/12,n,360,loan,300000,ROUND(PMT(rate,n,-loan),2))', + '=ROUND(IRR({-1000;300;400;500}),4)', + '=TEXT(DATE(2026,11,30),"dddd, mmmm d, yyyy")', +].join('\n') + const cmdBox = (text: string, prompt = '$') => `
${prompt}${esc(text)}
` const COPY_JS = `` @@ -105,21 +195,28 @@ export function homePage(cfg: Config): string { ${TERM} -

Try it now

One formula per line. This runs on the hosted engine (${L.anon.calls} free tries a day without a key).

-
+

Try it now

One formula per line, or pick from the examples below. This runs on the hosted engine (${L.anon.calls} free tries a day without a key).

+ +

Ask writes the formula on the c0mpute network and checks it on the engine; it lands in the box below. Each ask is one call.

+
No ^ operator in this engine: use POWER().
+

One engine, four ways in

The same calculation core everywhere: people in a terminal, agents over a socket.

diff --git a/cloud/test/app.test.ts b/cloud/test/app.test.ts index 6e5c166..7074b2a 100644 --- a/cloud/test/app.test.ts +++ b/cloud/test/app.test.ts @@ -1,6 +1,7 @@ import { describe, expect, test } from 'bun:test' import { signWebhook } from '@profullstack/coinpay-onboard' -import { createApp, configFromEnv, type Config } from '../src/app.ts' +import { createApp, configFromEnv, callTool, DEFAULT_LIMITS, type Config } from '../src/app.ts' +import { EXAMPLES } from '../src/page.ts' import { Store } from '../src/store.ts' import { contextCells, parseAnswer, type AiFn, type AiRequest } from '../src/ask.ts' @@ -151,6 +152,17 @@ describe('MCP', () => { }) }) +describe('showcase', () => { + test('every homepage example evaluates without an error', async () => { + const cfg = configFromEnv({ SK33P_BIN: BIN, SANDBOX: process.env.SANDBOX ?? '1' }) + const formulas = EXAMPLES.flatMap((g) => g.items.map(([f]) => f)) + expect(formulas.length).toBeGreaterThan(40) + const out: any = await callTool('eval', { formulas }, cfg, DEFAULT_LIMITS.pro) + const bad = out.results.filter((r: any) => !r.value || String(r.value).startsWith('#')) + expect(bad).toEqual([]) + }) +}) + describe('pages', () => { test('home, docs, llms.txt, ring descriptor, healthz', async () => { const { req } = setup() diff --git a/patches/0002-match-index-excel-semantics.patch b/patches/0002-match-index-excel-semantics.patch new file mode 100644 index 0000000..c05c3ca --- /dev/null +++ b/patches/0002-match-index-excel-semantics.patch @@ -0,0 +1,66 @@ +diff --git a/Libraries/SkSpreadSheet/source/SkFunctionSpreadSheet.cpp b/Libraries/SkSpreadSheet/source/SkFunctionSpreadSheet.cpp +index bd3d176..886a0c8 100644 +--- a/Libraries/SkSpreadSheet/source/SkFunctionSpreadSheet.cpp ++++ b/Libraries/SkSpreadSheet/source/SkFunctionSpreadSheet.cpp +@@ -1166,6 +1166,11 @@ namespace SkSpreadSheet { + StackElemToIndex(wArgRow, wRow); + if (wArgRange.Type() == tStackType::t_Range) { + wRange=wArgRange.Range(); ++ // Excel: on a single-row range the one index picks the column (sk33p patch 0003). ++ if (wRange!=nullptr && wRange->TopIndex()==wRange->IterateBottom() && wRange->IterateRight()>wRange->LeftIndex()) { ++ wCol=wRow; ++ wRow=1; ++ } + } + } + else { +@@ -1916,38 +1921,20 @@ namespace SkSpreadSheet { + } + } + } else if (wMatchTypeInt == 1) { +- // Greater or equal (ascending order) +- tIndex wSearchCol=wRange->LeftIndex(); ++ // Excel: the largest value <= lookup_value in an ascending list (sk33p patch 0002). ++ // Scan along the range's long side: a single row is searched across its columns. ++ const tBool wHorizontal = wRange->TopIndex() == wRange->IterateBottom() && wRange->IterateRight() > wRange->LeftIndex(); ++ const tIndex wCount = wHorizontal ? wRange->IterateRight() - wRange->LeftIndex() + 1 : wRange->IterateBottom() - wRange->TopIndex() + 1; + tIndex wLastMatch = 0; +- for(tIndex wRow=wRange->TopIndex();wRow<=wRange->IterateBottom();wRow++) { +- tCell* wCell=wColRowCellRange->Cell(wRow,wSearchCol); +- if (wCell!=nullptr) { +- tVariant wCellValue = wCell->Value(); +- if (wCellValue >= wSearch) { +- wPosition = wRow - wRange->TopIndex() + 1; // 1-based position +- // Clean up arguments before returning +- return(tStackElem(tVariant(wPosition))); +- } +- wLastMatch = wRow - wRange->TopIndex() + 1; +- } +- } +- // Check columns if range is horizontal +- tIndex wSearchRow=wRange->TopIndex(); +- for(tIndex wCol=wRange->LeftIndex();wCol<=wRange->IterateRight();wCol++) { +- tCell* wCell=wColRowCellRange->Cell(wSearchRow,wCol); +- if (wCell!=nullptr) { +- tVariant wCellValue = wCell->Value(); +- if (wCellValue >= wSearch) { +- wPosition = wCol - wRange->LeftIndex() + 1; // 1-based position +- // Clean up arguments before returning +- return(tStackElem(tVariant(wPosition))); +- } +- wLastMatch = wCol - wRange->LeftIndex() + 1; +- } ++ for (tIndex wI = 0; wI < wCount; wI++) { ++ tCell* wCell = wHorizontal ? wColRowCellRange->Cell(wRange->TopIndex(), wRange->LeftIndex() + wI) ++ : wColRowCellRange->Cell(wRange->TopIndex() + wI, wRange->LeftIndex()); ++ if (wCell == nullptr) continue; ++ tVariant wCellValue = wCell->Value(); ++ if (wCellValue > wSearch) break; // ascending: nothing later can be <= lookup_value ++ wLastMatch = wI + 1; // 1-based position + } +- // Return last position if no exact match found + if (wLastMatch > 0) { +- // Clean up arguments before returning + return(tStackElem(tVariant(wLastMatch))); + } + } else if (wMatchTypeInt == -1) { diff --git a/src/arrays.rs b/src/arrays.rs new file mode 100644 index 0000000..72fc9ec --- /dev/null +++ b/src/arrays.rs @@ -0,0 +1,174 @@ +//! Inline array constants for standalone formula evaluation. +//! +//! SkeeptoEngine accepts `{1,2,3}` syntactically, but many functions only work on +//! real cell ranges: IRR/COUNTIF/ROWS reject a constant outright, and SORT, UNIQUE, +//! TAKE, SUMPRODUCT, INDEX and MATCH silently ignore or mis-read one. Excel treats a +//! constant like a range, so for `eval` (a scratch workbook, nothing saved) each +//! constant is written into scratch cells and the formula points at that range. +//! Cell formulas in a user's workbook are never rewritten. +use crate::engine::{cell_name, Engine}; + +/// First scratch column (CV): eval formulas live in column A. +const SCRATCH_COL: usize = 100; + +/// One parsed constant: rows of raw items (numbers, booleans, or quoted strings). +type Constant = Vec>; + +/// Split `s` on `sep` outside double-quoted strings ("" is an escaped quote). +fn split_outside_quotes(s: &str, sep: char) -> Vec { + let mut out = Vec::new(); + let mut cur = String::new(); + let mut in_str = false; + let mut chars = s.chars().peekable(); + while let Some(c) = chars.next() { + if c == '"' { + cur.push(c); + if in_str && chars.peek() == Some(&'"') { + cur.push(chars.next().unwrap()); + } else { + in_str = !in_str; + } + } else if c == sep && !in_str { + out.push(std::mem::take(&mut cur)); + } else { + cur.push(c); + } + } + out.push(cur); + out +} + +fn parse_constant(body: &str) -> Constant { + split_outside_quotes(body, ';') + .iter() + .map(|row| split_outside_quotes(row, ',').into_iter().map(|v| v.trim().to_string()).collect()) + .collect() +} + +/// Cell input for one constant item: strings stay text even when they look numeric. +fn cell_input(item: &str) -> String { + if item.starts_with('"') { + format!("={item}") + } else { + item.to_string() + } +} + +/// Rewrite every `{...}` outside string literals into a scratch range on `e`. +/// Returns the rewritten formula; the formula is unchanged when it has no constants. +pub fn materialize(formula: &str, e: &mut Engine, next_col: &mut usize) -> Result { + if !formula.contains('{') { + return Ok(formula.to_string()); + } + let mut out = String::with_capacity(formula.len()); + let mut in_str = false; + let mut chars = formula.chars().peekable(); + while let Some(c) = chars.next() { + if c == '"' { + out.push(c); + if in_str && chars.peek() == Some(&'"') { + out.push(chars.next().unwrap()); + } else { + in_str = !in_str; + } + continue; + } + if c != '{' || in_str { + out.push(c); + continue; + } + // Collect the constant body up to the matching '}' (constants do not nest). + let mut body = String::new(); + let mut body_str = false; + let mut closed = false; + while let Some(d) = chars.next() { + if d == '"' { + body.push(d); + if body_str && chars.peek() == Some(&'"') { + body.push(chars.next().unwrap()); + } else { + body_str = !body_str; + } + } else if d == '}' && !body_str { + closed = true; + break; + } else { + body.push(d); + } + } + if !closed { + return Err(format!("unclosed array constant in {formula}")); + } + let rows = parse_constant(&body); + let width = rows.iter().map(Vec::len).max().unwrap_or(1).max(1); + let col0 = SCRATCH_COL + *next_col; + for (r, row) in rows.iter().enumerate() { + for (k, item) in row.iter().enumerate() { + if !item.is_empty() { + e.set(r + 1, col0 + k, &cell_input(item))?; + } + } + } + *next_col += width + 1; + let (r1, c1) = (rows.len().max(1), col0 + width - 1); + let range = if r1 == 1 && c1 == col0 { cell_name(1, col0) } else { format!("{}:{}", cell_name(1, col0), cell_name(r1, c1)) }; + out.push_str(&range); + } + Ok(out) +} + +/// Evaluate standalone formulas in a scratch engine, array constants included. +/// One result per formula, in order. +pub fn eval_formulas(formulas: &[String]) -> Result, String> { + let mut e = Engine::new()?; + let mut next_col = 0usize; + let mut cells = Vec::with_capacity(formulas.len()); + for f in formulas { + let text = if f.starts_with('=') { f.clone() } else { format!("={f}") }; + cells.push(materialize(&text, &mut e, &mut next_col)?); + } + for (i, text) in cells.iter().enumerate() { + e.set(i + 1, 1, text)?; + } + Ok((0..formulas.len()).map(|i| e.display(i + 1, 1)).collect()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn splits_respect_quotes() { + assert_eq!(split_outside_quotes(r#""a,b",c"#, ','), vec![r#""a,b""#, "c"]); + assert_eq!(split_outside_quotes(r#""say ""hi"", ok";2"#, ';'), vec![r#""say ""hi"", ok""#, "2"]); + } + + #[test] + fn parses_rows_and_columns() { + assert_eq!(parse_constant("1,2;3,4"), vec![vec!["1", "2"], vec!["3", "4"]]); + assert_eq!(parse_constant(r#""x","y""#), vec![vec![r#""x""#, r#""y""#]]); + } + + #[test] + fn constants_behave_like_ranges() { + let f = |s: &str| s.to_string(); + let got = eval_formulas(&[ + f("=ROUND(IRR({-1000;300;400;500}),4)"), + f("=SUMPRODUCT({1,2,3},{4,5,6})"), + f(r#"=TEXTJOIN(",",TRUE,SORT({3;1;2}))"#), + f("=MATCH(25,{10,20,30},1)"), + f("=INDEX({10,20,30},2)"), + f(r#"=COUNTIF({"a","b","a"},"a")"#), + f(r#"=TEXTJOIN("-",TRUE,"a,{b}","c")"#), + ]) + .unwrap(); + assert_eq!(got, vec!["0.089", "32", "1,2,3", "2", "20", "2", "a,{b}-c"]); + } + + #[test] + fn strings_stay_text() { + assert_eq!(cell_input(r#""123""#), r#"="123""#); + assert_eq!(cell_input("-4.5"), "-4.5"); + assert_eq!(cell_input("TRUE"), "TRUE"); + } +} diff --git a/src/cli.rs b/src/cli.rs index 89f59aa..14e39b1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -66,13 +66,8 @@ pub fn run(cmd: &str, rest: &[String]) -> Result<(), String> { if a.pos.is_empty() { return Err("eval needs at least one formula".into()); } - let mut e = Engine::new()?; - for (i, f) in a.pos.iter().enumerate() { - let text = if f.starts_with('=') { f.clone() } else { format!("={f}") }; - e.set(i + 1, 1, &text)?; - } - for i in 0..a.pos.len() { - println!("{}", e.display(i + 1, 1)); + for v in crate::arrays::eval_formulas(&a.pos)? { + println!("{v}"); } Ok(()) } diff --git a/src/main.rs b/src/main.rs index d4e7f82..ee77981 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod arrays; mod ask; mod cli; mod demo; diff --git a/src/mcp.rs b/src/mcp.rs index fdaedaf..723788e 100644 --- a/src/mcp.rs +++ b/src/mcp.rs @@ -84,12 +84,8 @@ fn call(name: &str, a: &Value) -> Result { .iter() .filter_map(|v| v.as_str().map(String::from)) .collect(); - let mut e = Engine::new()?; - for (i, f) in fs.iter().enumerate() { - let f = if f.starts_with('=') { f.clone() } else { format!("={f}") }; - e.set(i + 1, 1, &f)?; - } - Ok(json!(fs.iter().enumerate().map(|(i, f)| json!({"formula": f, "value": e.display(i + 1, 1)})).collect::>())) + let values = crate::arrays::eval_formulas(&fs)?; + Ok(json!(fs.iter().zip(values).map(|(f, v)| json!({"formula": f, "value": v})).collect::>())) } "read_range" => { let path = s(a, "path").ok_or("path is required")?; From 4e85202b102f6443a68c69b3389b92ea310ff86a Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Mon, 30 Nov 2026 17:18:59 +0000 Subject: [PATCH 2/2] test: array/MATCH/INDEX checks inside engine_end_to_end (one engine per process) Co-Authored-By: Claude Opus 5.5 --- src/arrays.rs | 16 +--------------- src/main.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/arrays.rs b/src/arrays.rs index 72fc9ec..c2f718a 100644 --- a/src/arrays.rs +++ b/src/arrays.rs @@ -149,21 +149,7 @@ mod tests { assert_eq!(parse_constant(r#""x","y""#), vec![vec![r#""x""#, r#""y""#]]); } - #[test] - fn constants_behave_like_ranges() { - let f = |s: &str| s.to_string(); - let got = eval_formulas(&[ - f("=ROUND(IRR({-1000;300;400;500}),4)"), - f("=SUMPRODUCT({1,2,3},{4,5,6})"), - f(r#"=TEXTJOIN(",",TRUE,SORT({3;1;2}))"#), - f("=MATCH(25,{10,20,30},1)"), - f("=INDEX({10,20,30},2)"), - f(r#"=COUNTIF({"a","b","a"},"a")"#), - f(r#"=TEXTJOIN("-",TRUE,"a,{b}","c")"#), - ]) - .unwrap(); - assert_eq!(got, vec!["0.089", "32", "1,2,3", "2", "20", "2", "a,{b}-c"]); - } + // Engine-backed checks live in main.rs's engine_end_to_end (one engine per process). #[test] fn strings_stay_text() { diff --git a/src/main.rs b/src/main.rs index ee77981..def3ff1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,6 +140,22 @@ mod tests { let ctx = body["context"].as_str().unwrap(); assert!(ctx.contains("active cell: A3") && ctx.contains("1\t10\n2\t20\n"), "{ctx}"); } + // Inline array constants behave like ranges, plus the MATCH/INDEX engine patch. + // Here (not in its own #[test]): the engine allows one instance per process. + { + let f = |s: &str| s.to_string(); + let got = crate::arrays::eval_formulas(&[ + f("=ROUND(IRR({-1000;300;400;500}),4)"), + f("=SUMPRODUCT({1,2,3},{4,5,6})"), + f(r#"=TEXTJOIN(",",TRUE,SORT({3;1;2}))"#), + f("=MATCH(25,{10,20,30},1)"), + f("=INDEX({10,20,30},2)"), + f(r#"=COUNTIF({"a","b","a"},"a")"#), + f(r#"=TEXTJOIN("-",TRUE,"a,{b}","c")"#), + ]) + .unwrap(); + assert_eq!(got, vec!["0.089", "32", "1,2,3", "2", "20", "2", "a,{b}-c"]); + } let _ = std::fs::remove_dir_all(&dir); }