|
1 | 1 | import { functionRegistry } from "@odoo/o-spreadsheet-engine/functions/function_registry"; |
2 | | -import { compile, functionCache, Model } from "../../src"; |
| 2 | +import { compile, functionCache } from "../../src"; |
3 | 3 |
|
4 | | -import { createValidRange } from "../../src/helpers"; |
5 | 4 | import { CompiledFormula } from "../../src/types"; |
6 | 5 | import { addToRegistry, evaluateCell, evaluateCellFormat } from "../test_helpers/helpers"; |
7 | 6 |
|
@@ -264,84 +263,6 @@ describe("compile functions", () => { |
264 | 263 | }); |
265 | 264 | }); |
266 | 265 |
|
267 | | - describe("with meta arguments", () => { |
268 | | - beforeEach(() => { |
269 | | - addToRegistry(functionRegistry, "USEMETAARG", { |
270 | | - description: "function with a meta argument", |
271 | | - compute: () => true, |
272 | | - args: [{ name: "arg", description: "", type: ["META", "RANGE<META>"] }], |
273 | | - }); |
274 | | - addToRegistry(functionRegistry, "NOTUSEMETAARG", { |
275 | | - description: "any function", |
276 | | - compute: () => true, |
277 | | - args: [{ name: "arg", description: "", type: ["ANY"] }], |
278 | | - }); |
279 | | - }); |
280 | | - |
281 | | - test.each(["=USEMETAARG(A1)", "=USEMETAARG(B2)"])( |
282 | | - "function call requesting meta parameter", |
283 | | - (formula) => { |
284 | | - const compiledFormula = compiledBaseFunction(formula); |
285 | | - expect(compiledFormula.execute.toString()).toMatchSnapshot(); |
286 | | - } |
287 | | - ); |
288 | | - |
289 | | - test("throw error if parameter isn't cell/range reference", () => { |
290 | | - expect(compiledBaseFunction("=USEMETAARG(X8)").isBadExpression).toBe(false); |
291 | | - expect(compiledBaseFunction("=USEMETAARG($X$8)").isBadExpression).toBe(false); |
292 | | - expect(compiledBaseFunction("=USEMETAARG(Sheet42!X8)").isBadExpression).toBe(false); |
293 | | - expect(compiledBaseFunction("=USEMETAARG('Sheet 42'!X8)").isBadExpression).toBe(false); |
294 | | - |
295 | | - expect(compiledBaseFunction("=USEMETAARG(D3:Z9)").isBadExpression).toBe(false); |
296 | | - expect(compiledBaseFunction("=USEMETAARG($D$3:$Z$9)").isBadExpression).toBe(false); |
297 | | - expect(compiledBaseFunction("=USEMETAARG(Sheet42!$D$3:$Z$9)").isBadExpression).toBe(false); |
298 | | - expect(compiledBaseFunction("=USEMETAARG('Sheet 42'!D3:Z9)").isBadExpression).toBe(false); |
299 | | - |
300 | | - expect(compiledBaseFunction('=USEMETAARG("kikou")').isBadExpression).toBe(true); |
301 | | - expect(compiledBaseFunction('=USEMETAARG("")').isBadExpression).toBe(true); |
302 | | - expect(compiledBaseFunction("=USEMETAARG(TRUE)").isBadExpression).toBe(true); |
303 | | - expect(compiledBaseFunction("=USEMETAARG(SUM(1,2,3))").isBadExpression).toBe(true); |
304 | | - }); |
305 | | - |
306 | | - test("do not care about the value of the cell / range passed as a reference", () => { |
307 | | - const compiledFormula1 = compileFromCompleteFormula("=USEMETAARG(A1)"); |
308 | | - const compiledFormula2 = compileFromCompleteFormula("=USEMETAARG(A1:B2)"); |
309 | | - const compiledFormula3 = compileFromCompleteFormula("=NOTUSEMETAARG(A1)"); |
310 | | - const compiledFormula4 = compileFromCompleteFormula("=NOTUSEMETAARG(A1:B2)"); |
311 | | - |
312 | | - const m = new Model(); |
313 | | - |
314 | | - const refFn = jest.fn(); |
315 | | - const ensureRange = jest.fn(); |
316 | | - const getSymbolValue = jest.fn(); |
317 | | - |
318 | | - const ctx = { USEMETAARG: () => {}, NOTUSEMETAARG: () => {} }; |
319 | | - |
320 | | - const rangeA1 = createValidRange(m.getters, "ABC", "A1")!; |
321 | | - const rangeA1ToB2 = createValidRange(m.getters, "ABC", "A1:B2")!; |
322 | | - |
323 | | - compiledFormula1.execute([rangeA1], refFn, ensureRange, getSymbolValue, ctx); |
324 | | - expect(refFn).toHaveBeenCalledTimes(0); |
325 | | - expect(ensureRange).toHaveBeenCalledWith(rangeA1, true); |
326 | | - ensureRange.mockReset(); |
327 | | - |
328 | | - compiledFormula2.execute([rangeA1ToB2], refFn, ensureRange, getSymbolValue, ctx); |
329 | | - expect(refFn).toHaveBeenCalledTimes(0); |
330 | | - expect(ensureRange).toHaveBeenCalledWith(rangeA1ToB2, true); |
331 | | - ensureRange.mockReset(); |
332 | | - |
333 | | - compiledFormula3.execute([rangeA1], refFn, ensureRange, getSymbolValue, ctx); |
334 | | - expect(refFn).toHaveBeenCalledWith(rangeA1, false); |
335 | | - expect(ensureRange).toHaveBeenCalledTimes(0); |
336 | | - refFn.mockReset(); |
337 | | - |
338 | | - compiledFormula4.execute([rangeA1ToB2], refFn, ensureRange, getSymbolValue, ctx); |
339 | | - expect(refFn).toHaveBeenCalledTimes(0); |
340 | | - expect(ensureRange).toHaveBeenCalledWith(rangeA1ToB2, false); |
341 | | - refFn.mockReset(); |
342 | | - }); |
343 | | - }); |
344 | | - |
345 | 266 | test("function cache ignore spaces in functions", () => { |
346 | 267 | compiledBaseFunction("=SUM(A1)"); |
347 | 268 | expect(Object.keys(functionCache)).toEqual(["=SUM(|C|)"]); |
|
0 commit comments