spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ISREF] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-09 16:29:40
stats
4 file(s) changed, 43 insertions(+), 4 deletions(-)
files
src/Formulas/AllFormulas.ts
src/Formulas/Info.ts
tests/Formulas/InfoTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
  2index 8e342d7..f25217e 100644
  3--- a/src/Formulas/AllFormulas.ts
  4+++ b/src/Formulas/AllFormulas.ts
  5@@ -87,7 +87,8 @@ import {
  6   ISNONTEXT,
  7   ISEMAIL,
  8   ISURL,
  9-  N
 10+  N,
 11+  ISREF
 12 } from "./Info";
 13 import {
 14   CHOOSE
 15@@ -424,5 +425,6 @@ export {
 16   UNARY_PERCENT,
 17   MULTINOMIAL,
 18   BINOMDIST,
 19-  COVAR
 20+  COVAR,
 21+  ISREF
 22 }
 23\ No newline at end of file
 24diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
 25index 0b198b5..c4dee77 100644
 26--- a/src/Formulas/Info.ts
 27+++ b/src/Formulas/Info.ts
 28@@ -7,6 +7,9 @@ import {
 29 import {
 30   TypeConverter
 31 } from "../Utilities/TypeConverter";
 32+import {
 33+  Cell
 34+} from "../Cell";
 35 
 36 
 37 /**
 38@@ -132,6 +135,19 @@ var N = function (value) {
 39 };
 40 
 41 
 42+/**
 43+ * Tests if the content of one or several cells is a reference. Verifies the type of references in a cell or a range of
 44+ * cells. If an error occurs, the function returns a logical or numerical value.
 45+ * @param value - The value to be tested, to determine whether it is a reference.
 46+ * @returns {boolean}
 47+ * @constructor
 48+ */
 49+var ISREF = function (value) {
 50+  ArgsChecker.checkLength(arguments, 1, "ISREF");
 51+  return TypeConverter.firstValue(value) instanceof Cell;
 52+};
 53+
 54+
 55 export {
 56   NA,
 57   ISTEXT,
 58@@ -140,5 +156,6 @@ export {
 59   ISNONTEXT,
 60   ISEMAIL,
 61   ISURL,
 62-  N
 63+  N,
 64+  ISREF
 65 }
 66\ No newline at end of file
 67diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
 68index a1a6507..6f6bbed 100644
 69--- a/tests/Formulas/InfoTest.ts
 70+++ b/tests/Formulas/InfoTest.ts
 71@@ -6,7 +6,8 @@ import {
 72   ISNONTEXT,
 73   ISEMAIL,
 74   ISURL,
 75-  N
 76+  N,
 77+  ISREF
 78 } from "../../src/Formulas/Info";
 79 import * as ERRORS from "../../src/Errors";
 80 import {
 81@@ -14,6 +15,9 @@ import {
 82   catchAndAssertEquals,
 83   test
 84 } from "../Utils/Asserts";
 85+import {
 86+  Cell
 87+} from "../../src/Cell";
 88 
 89 
 90 test("NA", function(){
 91@@ -107,3 +111,13 @@ test("N", function(){
 92     NA.apply(this, []);
 93   }, ERRORS.NA_ERROR);
 94 });
 95+
 96+test("ISREF", function(){
 97+  assertEquals(ISREF("10"), false);
 98+  assertEquals(ISREF(false), false);
 99+  assertEquals(ISREF(new Cell("A1")), true);
100+  assertEquals(ISREF([new Cell("A1"), new Cell("A2"), new Cell("A3")]), true);
101+  catchAndAssertEquals(function() {
102+    ISREF.apply(this, []);
103+  }, ERRORS.NA_ERROR);
104+});
105diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
106index f23e273..bc6f782 100644
107--- a/tests/SheetFormulaTest.ts
108+++ b/tests/SheetFormulaTest.ts
109@@ -829,6 +829,12 @@ test("Sheet COVAR", function(){
110   assertFormulaEquals('=COVAR([2, 4, 5, 1], [7, 3, 1, 3])', -2);
111 });
112 
113+test("Sheet ISREF", function(){
114+  assertFormulaEquals('=ISREF(B1)', true);
115+  assertFormulaEquals('=ISREF(B1:B10)', true);
116+  assertFormulaEquals('=ISREF(100)', false);
117+});
118+
119 test("Sheet *", function(){
120   assertFormulaEquals('= 10 * 10', 100);
121   assertFormulaEquals('= 10 * 0', 0);