spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[NETWORKDAYS.INTL] adding type checks, tests
author
Ben Vogt <[email protected]>
date
2017-04-26 02:15:30
stats
2 file(s) changed, 15 insertions(+), 4 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index 52f836e..4fc2a5e 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -693,7 +693,8 @@ var NETWORKDAYS$INTL = function (...values) : number {
 6     var weekend = TypeCaster.firstValue(values[2]);
 7     if (typeof weekend === "string") {
 8       if (!/^[0-1]{6,}$/.test(weekend)) {
 9-        // TODO: throw error, it doesn't match
10+        throw new NumError("Function NETWORKDAYS.INTL parameter 3 requires a number in the format '0000011'. "
11+            + "Actual value is '" + weekend + "'");
12       }
13       var ws = weekend.split("");
14       for (var i = 0; i < ws.length; i++) {
15@@ -713,11 +714,12 @@ var NETWORKDAYS$INTL = function (...values) : number {
16           weekendDays = [weekend - 10];
17           break;
18         default:
19-          // TODO throw error, not a recognized number.
20-          break;
21+          throw new NumError("Function NETWORKDAYS.INTL parameter 3 requires a number in the range 1-7 or 11-17. "
22+              + "Actual number is " + weekend + ".");
23       }
24     } else {
25-      // TODO: Throw error.
26+      throw new ValueError("Function NETWORKDAYS.INTL parameter 4 expects number values. But '" + weekend
27+          + "' cannot be coerced to a number.")
28     }
29   } else {
30     weekendDays = [1, 6];
31diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
32index 29116ef..511e1ed 100644
33--- a/tests/DateFormulasTest.ts
34+++ b/tests/DateFormulasTest.ts
35@@ -77,7 +77,15 @@ catchAndAssertEquals(function() {
36 catchAndAssertEquals(function() {
37   NETWORKDAYS$INTL("1992-1-1", "1992-1-1", []);
38 }, ERRORS.REF_ERROR);
39-
40+catchAndAssertEquals(function() {
41+  NETWORKDAYS$INTL("1992-1-1", "1994-1-1", "000");
42+}, ERRORS.NUM_ERROR);
43+catchAndAssertEquals(function() {
44+  NETWORKDAYS$INTL("1992-1-1", "1994-1-1", 9);
45+}, ERRORS.NUM_ERROR);
46+catchAndAssertEquals(function() {
47+  NETWORKDAYS$INTL("1992-1-1", "1994-1-1", false);
48+}, ERRORS.VALUE_ERROR);
49 
50 
51 // Test NETWORKDAYS