spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Fixing Formulas.ADD to handle nested data structures
author
Ben Vogt <[email protected]>
date
2017-01-16 22:14:44
stats
2 file(s) changed, 11 insertions(+), 1 deletions(-)
files
src/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas.ts b/src/RawFormulas.ts
 2index b0bb0dd..7aee389 100644
 3--- a/src/RawFormulas.ts
 4+++ b/src/RawFormulas.ts
 5@@ -184,8 +184,12 @@ var AND = function (...values) {
 6   for (var i = 0; i < values.length; i++) {
 7     if (typeof values[i] === "string") {
 8       throw new CellError(ERRORS.VALUE_ERROR, "AND expects boolean values. But '" + values[i] + "' is a text and cannot be coerced to a boolean.")
 9-    }
10-    if (!values[i]) {
11+    } else if (values[i] instanceof Array) {
12+      if (!AND.apply(this, values[i])) {
13+        result = false;
14+        break;
15+      }
16+    } else if (!values[i]) {
17       result = false;
18       break;
19     }
20diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
21index 5e45162..f3dafd0 100644
22--- a/tests/FormulasTest.ts
23+++ b/tests/FormulasTest.ts
24@@ -99,6 +99,11 @@ catchAndAssertEquals(function() {
25 catchAndAssertEquals(function() {
26   return AND(1, "str");
27 }, ERRORS.VALUE_ERROR);
28+assertEquals(AND(0, [1, 1]), false);
29+assertEquals(AND(1, [1, 1]), true);
30+catchAndAssertEquals(function() {
31+  return AND(1, [1, "str"]);
32+}, ERRORS.VALUE_ERROR);
33 
34 
35 assertEquals(ARABIC("XIV"), 14);