f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/js/execution/ExecutorFormulaTest.ts
-rw-r--r--
2471
 1import { NameException } from "../../../main/js/errors/NameException";
 2import { runner, it, describe } from "../testutils/TestUtils";
 3
 4describe("Executor.execute - Formulas", function () {
 5  it("should call formulas without arguments", function () {
 6    runner().addCell("Alpha", "A1", "= TRUE()").addExpectedValue("Alpha", "A1", true).run();
 7    runner().addCell("Alpha", "A1", "= FALSE()").addExpectedValue("Alpha", "A1", false).run();
 8  });
 9
10  it("should call formulas with number arguments", function () {
11    runner().addCell("Alpha", "A1", "= ADD(3, 4)").addExpectedValue("Alpha", "A1", 7.0).run();
12  });
13
14  it("should call formulas with string arguments", function () {
15    runner()
16      .addCell("Alpha", "A1", '= CONCAT("3", "4")')
17      .addExpectedValue("Alpha", "A1", "34")
18      .run();
19  });
20
21  it("should call formulas with boolean arguments", function () {
22    runner()
23      .addCell("Alpha", "A1", "= CONCAT(TRUE, FALSE)")
24      .addExpectedValue("Alpha", "A1", "TRUEFALSE")
25      .run();
26  });
27
28  it("should call formulas with array literal arguments", function () {
29    runner()
30      .addCell("Alpha", "A1", "= CONCAT({TRUE}, {22.1, 22})")
31      .addExpectedValue("Alpha", "A1", "TRUE22.1")
32      .run();
33  });
34
35  it("should call formulas with range arguments", function () {
36    runner().addCell("Alpha", "A1", "= SUM(B1:B4)").addExpectedValue("Alpha", "A1", 0).run();
37    runner()
38      .addCell("Alpha", "A1", "= SUM(B1:B4)")
39      .addCell("Alpha", "B1", "= 3")
40      .addCell("Alpha", "B2", "= 4")
41      .addCell("Alpha", "B3", "= 5")
42      .addCell("Alpha", "B4", "= 6")
43      .addExpectedValue("Alpha", "A1", 18)
44      .run();
45  });
46
47  it("should call formulas with named range arguments", function () {
48    runner()
49      .addNamedRange("Values", "Alpha!B1:B4")
50      .addCell("Alpha", "A1", "= SUM(Values)")
51      .addCell("Alpha", "B1", "= 3")
52      .addCell("Alpha", "B2", "= 4")
53      .addCell("Alpha", "B3", "= 5")
54      .addCell("Alpha", "B4", "= 6")
55      .addExpectedValue("Alpha", "A1", 18)
56      .run();
57  });
58
59  it("should allow nested formulas", function () {
60    runner()
61      .addCell("Alpha", "A1", "= SUM(3, 4, 5, CONCAT(10, 10))")
62      .addExpectedValue("Alpha", "A1", 1022.0)
63      .run();
64  });
65
66  it("should return NAME error when formula does not exist", function () {
67    runner()
68      .addCell("Alpha", "A1", "= NOTFOUND(10, 20)")
69      .addExpectedValue("Alpha", "A1", new NameException())
70      .run();
71  });
72});