commit
message
Adding more formula tests for Sheet.ts
author
Ben Vogt <[email protected]>
date
2016-12-31 21:34:12
stats
3 file(s) changed,
35 insertions(+),
1 deletions(-)
files
src/Cell.ts
src/Sheet.ts
tests/SheetTest.ts
1diff --git a/src/Cell.ts b/src/Cell.ts
2index d8931a6..a21290b 100644
3--- a/src/Cell.ts
4+++ b/src/Cell.ts
5@@ -32,6 +32,12 @@ class Cell {
6 setError(error: any) {
7 this.error = error;
8 }
9+ getRenderedValue() : string {
10+ if (this.error !== null) {
11+ return this.value;
12+ }
13+ return this.error.toString()
14+ }
15 }
16
17 export {
18diff --git a/src/Sheet.ts b/src/Sheet.ts
19index 939a503..e966b5c 100644
20--- a/src/Sheet.ts
21+++ b/src/Sheet.ts
22@@ -535,7 +535,7 @@ var Sheet = (function () {
23 this.toString = function () {
24 var toReturn = "";
25 for (var key in this.matrix.data) {
26- toReturn += this.matrix.data[key].id + " " + this.matrix.data[key].formula + " " + this.matrix.data[key].value + "\n";
27+ toReturn += this.matrix.data[key].id + " " + this.matrix.data[key].formula + " " + this.matrix.data[key].value + " " + this.matrix.data[key].error + "\n";
28 }
29 return toReturn;
30 };
31diff --git a/tests/SheetTest.ts b/tests/SheetTest.ts
32index e34dfe2..d26f894 100644
33--- a/tests/SheetTest.ts
34+++ b/tests/SheetTest.ts
35@@ -1,5 +1,6 @@
36 import { Sheet } from "../src/Sheet"
37 import {assertEquals, assertArrayEquals} from "./utils/Asserts"
38+import { Errors } from "../src/Errors"
39
40 // Test setCell, getCell, valid
41 var sheet = new Sheet();
42@@ -75,3 +76,29 @@ assertEquals("195.4", K6.value);
43 assertEquals(SUM_REF_FORMULA, K6.formula);
44 assertEquals(null, K6.error);
45 assertArrayEquals(['K1', 'K2', 'K3', 'K4'], K6.dependencies);
46+
47+
48+//Test REF error
49+var sheet = new Sheet();
50+sheet.setCell("A1", "200");
51+sheet.setCell("A2", "200");
52+sheet.setCell("A3", "SUM(A1, A2)");
53+sheet.setCell("B1", "SUM(A3, B2)");
54+sheet.setCell("B2", "SUM(A1, B1)");
55+var B1 = sheet.getCell("B1");
56+assertEquals(null, B1.value);
57+assertEquals(Errors.get("REF"), B1.error);
58+assertArrayEquals(['A3', 'B2'], B1.dependencies);
59+var B2 = sheet.getCell("B2");
60+assertEquals(null, B2.value);
61+assertEquals(Errors.get("REF"), B2.error);
62+assertArrayEquals(['A1', 'B1'], B2.dependencies);
63+
64+// Test NAME error
65+var sheet = new Sheet();
66+sheet.setCell("A1", "1");
67+sheet.setCell("A2", "SUM(A1, NN)");
68+var A2 = sheet.getCell("A2");
69+assertEquals(null, A2.value);
70+assertEquals(Errors.get("NAME"), A2.error);
71+assertArrayEquals(['A1'], A2.dependencies);
72\ No newline at end of file