spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Sheet] making sure Error.Type is called properly with resulting errors
author
Ben Vogt <[email protected]>
date
2017-09-04 20:21:59
stats
4 file(s) changed, 18 insertions(+), 13 deletions(-)
files
TODO.md
src/Formulas/Info.ts
src/Sheet.ts
tests/SheetFormulaTest.ts
 1diff --git a/TODO.md b/TODO.md
 2index 0eb49fb..304c36d 100644
 3--- a/TODO.md
 4+++ b/TODO.md
 5@@ -20,8 +20,11 @@ We could give each function a type-array that matches the arguments, and could b
 6 ### Fix documentation regular expression, it is butchering URLs.
 7 
 8 
 9-### ERROR.TYPE, ISERR, ISERROR, ISNA need to be called inside a try-catch-block inside the Parser or Sheet.
10-See documentation for ERROR.TYPE for more information.
11+### ISERR, ISERROR, ISNA need to be called inside a try-catch-block inside the Parser or Sheet.
12+
13+
14+### Cells/Sheet/Parser should be able to parse raw errors in the format `#N/A`
15+All errors should be able to be input/thrown in this way.
16 
17 
18 ### Meta-Formulas to write
19diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
20index 582549d..21752cc 100644
21--- a/src/Formulas/Info.ts
22+++ b/src/Formulas/Info.ts
23@@ -156,9 +156,6 @@ let ISREF = function (value) {
24  * @param value - Contains either the address/reference of the cell in which the error occurs, or the error directly.
25  * Eg: `=ERRORTYPE(NA())`
26  * @constructor
27- * TODO: This formula, while written correctly in javascript, needs to be called inside of a try-catch-block inside the
28- * Parser/Sheet. Otherwise the errors thrown by nested formulas break through. Eg: `=ERRORTYPE(NA())`, NA bubbles up.
29- * Once this is done, we should test it inside SheetFormulaTest.ts
30  */
31 let ERRORTYPE = function (value) {
32   ArgsChecker.checkLength(arguments, 1, "ERRORTYPE");
33diff --git a/src/Sheet.ts b/src/Sheet.ts
34index 5468b00..e99bf4d 100644
35--- a/src/Sheet.ts
36+++ b/src/Sheet.ts
37@@ -474,10 +474,6 @@ let Sheet = (function () {
38           throw new RefError("Reference does not exist.");
39         }
40       }
41-      // // check if any error occurs
42-      // if (!cell.isBlank() && cell.getError()) {
43-      //   throw cell.getError();
44-      // }
45       return cell;
46     },
47 
48@@ -536,6 +532,12 @@ let Sheet = (function () {
49       error = e;
50     }
51 
52+    if (result instanceof Error) {
53+      return {
54+        error: result,
55+        result: null
56+      }
57+    }
58     return {
59       error: error,
60       result: result
61diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
62index b046a33..7d9178d 100644
63--- a/tests/SheetFormulaTest.ts
64+++ b/tests/SheetFormulaTest.ts
65@@ -968,20 +968,24 @@ test("Sheet TO_TEXT", function(){
66 });
67 
68 test("Sheet ERROR.TYPE", function(){
69-
70   let sheet = new Sheet();
71   sheet.setCell("M1", "= 1/0");
72   sheet.setCell("A1", "=ERROR.TYPE(M1)");
73   assertEquals(sheet.getCell("A1").getValue(), 2);
74-
75   // Divide by zero error should be caught by formula
76   assertFormulaEquals('=ERROR.TYPE(1/0)', 2);
77-
78   // NA error should also be caught by formula
79   assertFormulaEquals('=ERROR.TYPE(NA())', 7);
80-
81+  // name error should also be caught by formula
82+  assertFormulaEquals('=ERROR.TYPE(NOTAFUNCTION())', 5);
83+  // num error should also be caught by formula
84+  assertFormulaEquals('=ERROR.TYPE(ACOS(44))', 6);
85   // Parse error should bubble up to cell
86   assertFormulaEqualsError('=ERROR.TYPE(10e)', PARSE_ERROR);
87+  // Ref to empty cell should bubble up to cell
88+  assertFormulaEqualsError('=ERROR.TYPE(M8)', NA_ERROR);
89+  // Non-error value passed in should cause NA_ERROR
90+  assertFormulaEqualsError('=ERROR.TYPE(10)', NA_ERROR);
91 });
92 
93 test("Sheet parsing error", function(){