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/formulas/info/ERRORTYPETest.ts
-rw-r--r--
2790
 1import { assert } from "chai";
 2import { it, describe } from "../../testutils/TestUtils";
 3import { stub } from "sinon";
 4import { DivException } from "../../../../main/js/errors/DivException";
 5import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
 6import { NAException } from "../../../../main/js/errors/NAException";
 7import { NameException } from "../../../../main/js/errors/NameException";
 8import { NullException } from "../../../../main/js/errors/NullException";
 9import { NumException } from "../../../../main/js/errors/NumException";
10import { ParseException } from "../../../../main/js/errors/ParseException";
11import { RefException } from "../../../../main/js/errors/RefException";
12import { ValueException } from "../../../../main/js/errors/ValueException";
13import { ERRORTYPE } from "../../../../main/js/formulas/info/ERRORTYPE";
14import { Grid } from "../../../../main/js/models/common/Grid";
15import {
16  CollateralLookupFunction,
17  Computed,
18  LookupFunction,
19} from "../../../../main/js/models/common/Types";
20import { CommonModels } from "../../testutils/CommonModels";
21
22describe("ERRORTYPE", function () {
23  it("should return code for errors", function () {
24    assert.deepEqual(ERRORTYPE.SELF.run(null, new NullException()), 1);
25    assert.deepEqual(ERRORTYPE.SELF.run(null, new DivException()), 2);
26    assert.deepEqual(ERRORTYPE.SELF.run(null, new ValueException()), 3);
27    assert.deepEqual(ERRORTYPE.SELF.run(null, new RefException()), 4);
28    assert.deepEqual(ERRORTYPE.SELF.run(null, new NameException()), 5);
29    assert.deepEqual(ERRORTYPE.SELF.run(null, new NumException()), 6);
30    assert.deepEqual(ERRORTYPE.SELF.run(null, new NAException()), 7);
31    assert.deepEqual(ERRORTYPE.SELF.run(null, new ParseException()), 8);
32  });
33
34  it("should use lookup", function () {
35    const lookup = stub();
36    const collateralLookup = stub();
37    const F = new ERRORTYPE(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
38    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(new DivException());
39    assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), 2);
40    assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
41    assert.equal(collateralLookup.callCount, 1);
42    assert.isTrue(lookup.notCalled);
43  });
44
45  it("should handle grids", function () {
46    assert.deepEqual(
47      ERRORTYPE.SELF.run(null, Grid.from<Computed>([[new NullException()], [10]])),
48      1
49    );
50  });
51
52  it("should return error when argument lengths are wrong", function () {
53    assert.deepEqual((ERRORTYPE.SELF.run(null) as NAException).name, F7ExceptionName.NA);
54    assert.deepEqual(
55      (ERRORTYPE.SELF.run(null, "Too many") as NAException).name,
56      F7ExceptionName.NA
57    );
58  });
59});