spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Adding a few more Cell.ts tests.
author
Ben Vogt <[email protected]>
date
2016-12-29 21:01:30
stats
11 file(s) changed, 77 insertions(+), 2 deletions(-)
files
package.json
tests/A1CellKeyTest.ts
tests/CellTest.ts
tests/utils/Asserts.ts
ts/A1CellKey.ts
src/A1CellKey.ts
ts/Cell.ts
src/Cell.ts
ts/Errors.ts
src/Errors.ts
ts/Main.ts
src/Main.ts
ts/Parser.d.ts
src/Parser.d.ts
ts/Sheet.ts
src/Sheet.ts
tsconfig.json
  1diff --git a/package.json b/package.json
  2index c7f0c48..5a13261 100644
  3--- a/package.json
  4+++ b/package.json
  5@@ -3,7 +3,8 @@
  6   "version": "1.0.0",
  7   "description": "TypeScript implementation of a spreadsheet.",
  8   "scripts": {
  9-    "build": "tsc && cp lib/parser.js output/"
 10+    "build": "tsc && cp lib/parser.js output/",
 11+    "test": "tsc --outDir test_output tests/*.ts && node test_output/tests/*.js && echo Tests Pass"
 12   },
 13   "author": "vogtb <bvogt at gmail.com>",
 14   "license": "MIT",
 15diff --git a/ts/A1CellKey.ts b/src/A1CellKey.ts
 16similarity index 100%
 17rename from ts/A1CellKey.ts
 18rename to src/A1CellKey.ts
 19diff --git a/ts/Cell.ts b/src/Cell.ts
 20similarity index 84%
 21rename from ts/Cell.ts
 22rename to src/Cell.ts
 23index 501b904..d8931a6 100644
 24--- a/ts/Cell.ts
 25+++ b/src/Cell.ts
 26@@ -1,3 +1,5 @@
 27+import {A1CellKey} from "./A1CellKey";
 28+
 29 class Cell {
 30   public formula: string;
 31   public value: string;
 32@@ -7,11 +9,15 @@ class Cell {
 33   public row: number;
 34   public col: number;
 35   constructor(formula: string, id: string) {
 36+    var key = new A1CellKey(id);
 37+
 38     this.formula = formula;
 39     this.value = "";
 40     this.dependencies = [];
 41     this.error = null;
 42     this.id = id;
 43+    this.row = key.getY();
 44+    this.col = key.getX();
 45   }
 46   updateDependencies(dependencies: Array<string>) {
 47     for (var index in dependencies) {
 48diff --git a/ts/Errors.ts b/src/Errors.ts
 49similarity index 100%
 50rename from ts/Errors.ts
 51rename to src/Errors.ts
 52diff --git a/ts/Main.ts b/src/Main.ts
 53similarity index 100%
 54rename from ts/Main.ts
 55rename to src/Main.ts
 56diff --git a/ts/Parser.d.ts b/src/Parser.d.ts
 57similarity index 100%
 58rename from ts/Parser.d.ts
 59rename to src/Parser.d.ts
 60diff --git a/ts/Sheet.ts b/src/Sheet.ts
 61similarity index 100%
 62rename from ts/Sheet.ts
 63rename to src/Sheet.ts
 64diff --git a/tests/A1CellKeyTest.ts b/tests/A1CellKeyTest.ts
 65new file mode 100644
 66index 0000000..3070412
 67--- /dev/null
 68+++ b/tests/A1CellKeyTest.ts
 69@@ -0,0 +1,26 @@
 70+import { A1CellKey } from "../src/A1CellKey"
 71+import { assertEquals } from "./utils/Asserts"
 72+
 73+//Test constructor
 74+var one = new A1CellKey("A1");
 75+assertEquals("A", one.getColumn());
 76+assertEquals(1, one.getRow());
 77+assertEquals(0, one.getX());
 78+assertEquals(0, one.getY());
 79+var two = new A1CellKey("Z4563534");
 80+assertEquals("Z", two.getColumn());
 81+assertEquals(4563534, two.getRow());
 82+assertEquals(25, two.getX());
 83+assertEquals(4563533, two.getY());
 84+
 85+//Test static constructor
 86+var one = A1CellKey.of(0, 0);
 87+assertEquals("A", one.getColumn());
 88+assertEquals(1, one.getRow());
 89+assertEquals(0, one.getX());
 90+assertEquals(0, one.getY());
 91+var two = A1CellKey.of(25, 4563533);
 92+assertEquals("Z", two.getColumn());
 93+assertEquals(4563534, two.getRow());
 94+assertEquals(25, two.getX());
 95+assertEquals(4563533, two.getY());
 96\ No newline at end of file
 97diff --git a/tests/CellTest.ts b/tests/CellTest.ts
 98new file mode 100644
 99index 0000000..44b733e
100--- /dev/null
101+++ b/tests/CellTest.ts
102@@ -0,0 +1,17 @@
103+import { Cell } from "../src/Cell"
104+import { assertEquals, assertArrayEquals } from "./utils/Asserts"
105+
106+//Test constructor
107+var cell = new Cell("0", "A1");
108+assertEquals(cell.col, 0);
109+assertEquals(cell.row, 0);
110+assertArrayEquals(cell.dependencies, []);
111+assertEquals(cell.id, "A1");
112+assertEquals(cell.formula, "0");
113+
114+//Test updateDependencies
115+var one = new Cell("0", "A1");
116+one.updateDependencies(["B2", "C1", "D12", "D13"]);
117+assertArrayEquals(one.dependencies, ["B2", "C1", "D12", "D13"]);
118+one.updateDependencies(["M4"]);
119+assertArrayEquals(one.dependencies, ["B2", "C1", "D12", "D13", "M4"]);
120diff --git a/tests/utils/Asserts.ts b/tests/utils/Asserts.ts
121new file mode 100644
122index 0000000..f96f76f
123--- /dev/null
124+++ b/tests/utils/Asserts.ts
125@@ -0,0 +1,24 @@
126+function assertEquals(expected, actual) {
127+  if (expected != actual) {
128+    console.log(expected, "not equal to", actual);
129+    throw Error();
130+  }
131+}
132+
133+function assertArrayEquals(expected: Array<any>, actual: Array<any>) {
134+  if (expected.length != actual.length) {
135+    console.log(expected, "not equal to", actual);
136+    throw Error();
137+  }
138+  for (var index in expected) {
139+    if (expected[index] != actual[index]) {
140+      console.log(expected, "not equal to", actual);
141+      throw Error();
142+    }
143+  }
144+}
145+
146+export {
147+  assertEquals,
148+  assertArrayEquals
149+}
150\ No newline at end of file
151diff --git a/tsconfig.json b/tsconfig.json
152index f867366..1ba5ad0 100644
153--- a/tsconfig.json
154+++ b/tsconfig.json
155@@ -6,6 +6,6 @@
156     "outDir": "output"
157   },
158   "files": [
159-    "ts/main.ts"
160+    "src/Main.ts"
161   ]
162 }