commit
message
[SheetBasicTest] testing sheet, since testing parser directly doesn't make a lot of sense
author
Ben Vogt <[email protected]>
date
2017-12-20 02:09:50
stats
4 file(s) changed,
260 insertions(+),
262 deletions(-)
files
tests/Parser/ParserTest.ts
tests/SheetBasicTests.ts
tests/SheetFormulaTest.ts
tests/SheetTest.ts
1diff --git a/tests/Parser/ParserTest.ts b/tests/Parser/ParserTest.ts
2deleted file mode 100644
3index a77fc51..0000000
4--- a/tests/Parser/ParserTest.ts
5+++ /dev/null
6@@ -1,227 +0,0 @@
7-import {
8- FormulaParser
9-} from "../../src/Parser/Parser";
10-import {
11- DIV_ZERO_ERROR, NA_ERROR, NULL_ERROR, NUM_ERROR, PARSE_ERROR,
12- REF_ERROR, VALUE_ERROR
13-} from "../../src/Errors";
14-import {assertEquals, catchAndAssertEquals, test} from "../Utils/Asserts";
15-import {HelperUtils} from "../../src/Parser/HelperUtils";
16-import {DataStore} from "../../src/Parser/DataStore";
17-
18-
19-let parser = FormulaParser(new HelperUtils(new DataStore()));
20-parser.yy.obj ="A1";
21-
22-
23-test("Declare number", function () {
24- assertEquals(parser.parse('5'), 5);
25-});
26-
27-test("Number multiplication", function () {
28- assertEquals(parser.parse('5*5'), 25);
29-});
30-
31-
32-
33-test("Parse but throw parse error", function(){
34- // assertEquals(parser.parse('=10e'), PARSE_ERROR);
35- // assertEquals(parser.parse('= SUM('), PARSE_ERROR);
36-});
37-
38-test("Parse & operator", function(){
39- assertEquals(parser.parse('"hey"&" "&"there"'), "hey there");
40-});
41-
42-test("Parse * operator", function(){
43- assertEquals(parser.parse('10 * 10'), 100);
44- assertEquals(parser.parse('10 * 0'), 0);
45- assertEquals(parser.parse('1 * 1'), 1);
46-});
47-
48-test("Parse / operator", function(){
49- assertEquals(parser.parse('10 / 2'), 5);
50- assertEquals(parser.parse('10 / 1'), 10);
51- assertEquals(parser.parse('1 / 1'), 1);
52- assertEquals(parser.parse('0 / 1'), 0);
53- assertEquals(parser.parse('"1" / 1'), 1);
54- assertEquals(parser.parse('"500" / 1'), 500);
55- catchAndAssertEquals(function () {
56- parser.parse(' 10 / 0');
57- }, DIV_ZERO_ERROR);
58- catchAndAssertEquals(function () {
59- parser.parse('0 / 0')
60- }, DIV_ZERO_ERROR);
61- // assertEquals(parser.parse('P9 / 1'), 0);
62-});
63-
64-test("Parse ^ operator", function(){
65- assertEquals(parser.parse('10 ^ 10'), 10000000000);
66- assertEquals(parser.parse('10 ^ 0'), 1);
67- assertEquals(parser.parse('1 ^ 1'), 1);
68- assertEquals(parser.parse('2 ^ 10'), 1024);
69-});
70-
71-test("Parse comparison operators on numbers", function(){
72- assertEquals(parser.parse('1 = 1'), true);
73- assertEquals(parser.parse('1 = 0'), false);
74- assertEquals(parser.parse('1 < 2'), true);
75- assertEquals(parser.parse('1 < 0'), false);
76- assertEquals(parser.parse('1 < 1'), false);
77- assertEquals(parser.parse('1 <= 0'), false);
78- assertEquals(parser.parse('1 <= 1'), true);
79- assertEquals(parser.parse('1 <= 2'), true);
80- assertEquals(parser.parse('1 >= 1'), true);
81- assertEquals(parser.parse('2 >= 1'), true);
82- assertEquals(parser.parse('1 >= 0'), true);
83- assertEquals(parser.parse('1 >= 2'), false);
84- assertEquals(parser.parse('1 <> 1'), false);
85- assertEquals(parser.parse('1 <> 2'), true);
86-});
87-
88-test("Parse comparison operators on strings", function(){
89- assertEquals(parser.parse('"abc" = "abc"'), true);
90- assertEquals(parser.parse('"abc" = "xyz"'), false);
91- assertEquals(parser.parse('"abc" < "abc"'), false);
92- assertEquals(parser.parse('"abc" < "xyz"'), true);
93- assertEquals(parser.parse('"abc" <= "abc"'), true);
94- assertEquals(parser.parse('"abc" <= "xyz"'), true);
95- assertEquals(parser.parse('"xyz" <= "abc"'), false);
96- assertEquals(parser.parse('"abc" >= "abc"'), true);
97- assertEquals(parser.parse('"abc" >= "zyx"'), false);
98- assertEquals(parser.parse('"xyz" >= "abc"'), true);
99- assertEquals(parser.parse('"abc" <> "abc"'), false);
100- assertEquals(parser.parse('"abc" <> "zyz"'), true);
101-});
102-
103-test("Parse comparison operators on boolean", function(){
104- assertEquals(parser.parse('TRUE = TRUE'), true);
105- assertEquals(parser.parse('TRUE = FALSE'), false);
106- assertEquals(parser.parse('FALSE = FALSE'), true);
107- assertEquals(parser.parse('TRUE > TRUE'), false);
108- assertEquals(parser.parse('TRUE > FALSE'), true);
109- assertEquals(parser.parse('FALSE > FALSE'), false);
110- assertEquals(parser.parse('TRUE <= TRUE'), true);
111- assertEquals(parser.parse('TRUE <= FALSE'), false);
112- assertEquals(parser.parse('FALSE <= TRUE'), true);
113- assertEquals(parser.parse('TRUE >= TRUE'), true);
114- assertEquals(parser.parse('TRUE >= FALSE'), true);
115- assertEquals(parser.parse('FALSE >= TRUE'), false);
116- assertEquals(parser.parse('TRUE <> TRUE'), false);
117- assertEquals(parser.parse('FALSE <> FALSE'), false);
118- assertEquals(parser.parse('TRUE <> FALSE'), true);
119- assertEquals(parser.parse('FALSE <> TRUE'), true);
120-});
121-
122-test("Parse operators, order of operations", function(){
123- assertEquals(parser.parse('10 + -10'), 0);
124- assertEquals(parser.parse('10 + -10 = 0'), true);
125- assertEquals(parser.parse('10 + -10 = 0 & "str"'), false);
126- assertEquals(parser.parse('-10%'), -0.1);
127- assertEquals(parser.parse('10 + 10%'), 10.1);
128- assertEquals(parser.parse('-10 + 10%'), -9.9);
129- assertEquals(parser.parse('-10 - +10%'), -10.1);
130- assertEquals(parser.parse('2^-10 + 10%'), 0.1009765625);
131- assertEquals(parser.parse('4 * 5 / 2'), 10);
132- assertEquals(parser.parse('4 / 5 * 4'), 3.2);
133- assertEquals(parser.parse('2^2*5'), 20);
134- assertEquals(parser.parse('2^(2*5)'), 1024);
135-});
136-
137-test("Parse and throw error literal", function () {
138- assertEquals(parser.parse('#N/A').name, NA_ERROR);
139- assertEquals(parser.parse('#NUM!').name, NUM_ERROR);
140- assertEquals(parser.parse('#REF!').name, REF_ERROR);
141- assertEquals(parser.parse('#NULL!').name, NULL_ERROR);
142- assertEquals(parser.parse('#ERROR').name, PARSE_ERROR);
143- assertEquals(parser.parse('#DIV/0!').name, DIV_ZERO_ERROR);
144- assertEquals(parser.parse('#VALUE!').name, VALUE_ERROR);
145-});
146-
147-test("Parse plain numbers", function() {
148- assertEquals(parser.parse('10'), 10);
149- // assertEquals(parser.parse('.1'), 0.1); // TODO: Fails because our parser doesn't expect a decimal right away.
150- assertEquals(parser.parse('+1'), 1);
151- assertEquals(parser.parse('-1'), -1);
152- assertEquals(parser.parse('++1'), 1);
153- assertEquals(parser.parse('--1'), 1);
154- assertEquals(parser.parse('10e1'), 100);
155- assertEquals(parser.parse('0e1'), 0);
156- // assertEquals(parser.parse('0.e1'), 0); // TODO: Fails. After decimal, finds 'e' and thinks it's a variable.
157- assertEquals(parser.parse('-10e1'), -100);
158- assertEquals(parser.parse('+10e1'), 100);
159- assertEquals(parser.parse('++10e1'), 100);
160- assertEquals(parser.parse('--10e1'), 100);
161-});
162-
163-test("Parse complex numbers and math", function(){
164- assertEquals(parser.parse('"10" + 10'), 20);
165- assertEquals(parser.parse('"10.111111" + 0'), 10.111111);
166- assertEquals(parser.parse('10%'), 0.1);
167- assertEquals(parser.parse('10% + 1'), 1.1);
168- assertEquals(parser.parse('"10e1" + 0'), 100);
169- assertEquals(parser.parse('10e1'), 100);
170- assertEquals(parser.parse('10e-1'), 1);
171- assertEquals(parser.parse('10e+1'), 100);
172- assertEquals(parser.parse('10E1'), 100);
173- assertEquals(parser.parse('10E-1'), 1);
174- assertEquals(parser.parse('10E+1'), 100);
175- assertEquals(parser.parse('"1,000,000" + 0'), 1000000);
176- assertEquals(parser.parse('"+$10.00" + 0'), 10);
177- assertEquals(parser.parse('"-$10.00" + 0'), -10);
178- assertEquals(parser.parse('"$+10.00" + 0'), 10);
179- assertEquals(parser.parse('"$-10.00" + 0'), -10);
180- assertEquals(parser.parse('"10" + 10'), 20);
181- assertEquals(parser.parse('"10.111111" + 0'), 10.111111);
182- assertEquals(parser.parse('10%'), 0.1);
183- assertEquals(parser.parse('10% + 1'), 1.1);
184- assertEquals(parser.parse('"10e1" + 0'), 100);
185- assertEquals(parser.parse('10e1'), 100);
186- assertEquals(parser.parse('10e-1'), 1);
187- assertEquals(parser.parse('10e+1'), 100);
188- assertEquals(parser.parse('10E1'), 100);
189- assertEquals(parser.parse('10E-1'), 1);
190- assertEquals(parser.parse('10E+1'), 100);
191- assertEquals(parser.parse('"1,000,000" + 0'), 1000000);
192- catchAndAssertEquals(function () {
193- parser.parse('"10e" + 10');
194- }, VALUE_ERROR);
195- assertEquals(parser.parse('"+$10.00" + 0'), 10);
196- assertEquals(parser.parse('"-$10.00" + 0'), -10);
197- assertEquals(parser.parse('"$+10.00" + 0'), 10);
198- assertEquals(parser.parse('"$-10.00" + 0'), -10);
199-});
200-
201-test("Parse strings", function(){
202- assertEquals(parser.parse('"str"'), "str");
203- assertEquals(parser.parse('"str"&"str"'), "strstr");
204- catchAndAssertEquals(function () {
205- parser.parse('"str"+"str"');
206- }, VALUE_ERROR);
207- // assertEquals("='str'", PARSE_ERROR); // TODO: Parses, but we should not allow single-quote strings.
208-});
209-
210-test("Parse boolean literals", function(){
211- assertEquals(parser.parse('TRUE'), true);
212- assertEquals(parser.parse('true'), true);
213- assertEquals(parser.parse('FALSE'), false);
214- assertEquals(parser.parse('false'), false);
215-});
216-
217-test("Parse comparison logic inside parentheses", function(){
218- // assertEquals(parser.parse('(1=1)'), true); // TODO: Fails because we compute the value, rather than checking equality
219- // assertEquals(parser.parse('(1=2)'), false); // TODO: Fails because we compute the value, rather than checking equality
220- assertEquals(parser.parse('(1=1)+2'), 3);
221-});
222-
223-
224-test("Parse range literal", function(){
225- // assertEqualsArray('=[1, 2, 3]', [1, 2, 3]); // TODO: Fails because we've not implemented array-level parsing.
226- // assertEqualsArray('=[]', []);
227- // assertEqualsArray('=["str", "str"]', ["str", "str"]);
228- // assertEqualsArray('=["str", [1, 2, 3], [1]]', ["str", [1, 2, 3], [1]]);
229-});
230-
231-
232-
233-assertEquals(parser.parse('"one" = "one"'), true);
234diff --git a/tests/SheetBasicTests.ts b/tests/SheetBasicTests.ts
235new file mode 100644
236index 0000000..95426bc
237--- /dev/null
238+++ b/tests/SheetBasicTests.ts
239@@ -0,0 +1,214 @@
240+import {
241+ DIV_ZERO_ERROR,
242+ NA_ERROR,
243+ NULL_ERROR,
244+ NUM_ERROR,
245+ PARSE_ERROR,
246+ REF_ERROR,
247+ VALUE_ERROR
248+} from "../src/Errors";
249+import {assertFormulaEquals, assertFormulaEqualsError, test} from "./Utils/Asserts";
250+
251+test("Sheet, declare number", function () {
252+ assertFormulaEquals('=5', 5);
253+});
254+
255+test("Sheet, declare string", function () {
256+ assertFormulaEquals('="str"', "str");
257+});
258+
259+test("Sheet, number multiplication", function () {
260+ assertFormulaEquals('=5*5', 25);
261+});
262+
263+test("Sheet, parse but throw parse error", function(){
264+ // assertEquals(parser.parse('=10e'), PARSE_ERROR);
265+ // assertEquals(parser.parse('= SUM('), PARSE_ERROR);
266+});
267+
268+test("Sheet, parse & operator", function(){
269+ assertFormulaEquals('="hey"&" "&"there"', "hey there");
270+});
271+
272+test("Sheet, parse * operator", function(){
273+ assertFormulaEquals('=10 * 10', 100);
274+ assertFormulaEquals('=10 * 0', 0);
275+ assertFormulaEquals('=1 * 1', 1);
276+ assertFormulaEquals('=1 * 0', 0);
277+ assertFormulaEquals('=0 * 0', 0);
278+});
279+
280+test("Sheet, parse / operator", function(){
281+ assertFormulaEquals('=10 / 2', 5);
282+ assertFormulaEquals('=10 / 1', 10);
283+ assertFormulaEquals('=1 / 1', 1);
284+ assertFormulaEquals('=0 / 1', 0);
285+ assertFormulaEquals('="1" / 1', 1);
286+ assertFormulaEquals('="500" / 1', 500);
287+ assertFormulaEqualsError('=10 / 0', DIV_ZERO_ERROR);
288+ assertFormulaEqualsError('=0 / 0', DIV_ZERO_ERROR);
289+ // assertEquals(parser.parse('P9 / 1'), 0);
290+});
291+
292+test("Sheet, parse ^ operator", function(){
293+ assertFormulaEquals('=10 ^ 10', 10000000000);
294+ assertFormulaEquals('=10 ^ 0', 1);
295+ assertFormulaEquals('=1 ^ 1', 1);
296+ assertFormulaEquals('=2 ^ 10', 1024);
297+});
298+
299+test("Sheet, parse comparison operators on numbers", function(){
300+ assertFormulaEquals('=1 = 1', true);
301+ assertFormulaEquals('=1 = 0', false);
302+ assertFormulaEquals('=1 < 2', true);
303+ assertFormulaEquals('=1 < 0', false);
304+ assertFormulaEquals('=1 < 1', false);
305+ assertFormulaEquals('=1 <= 0', false);
306+ assertFormulaEquals('=1 <= 1', true);
307+ assertFormulaEquals('=1 <= 2', true);
308+ assertFormulaEquals('=1 >= 1', true);
309+ assertFormulaEquals('=2 >= 1', true);
310+ assertFormulaEquals('=1 >= 0', true);
311+ assertFormulaEquals('=1 >= 2', false);
312+ assertFormulaEquals('=1 <> 1', false);
313+ assertFormulaEquals('=1 <> 2', true);
314+});
315+
316+test("Sheet, parse comparison operators on strings", function(){
317+ assertFormulaEquals('="abc" = "abc"', true);
318+ assertFormulaEquals('="abc" = "xyz"', false);
319+ assertFormulaEquals('="abc" < "abc"', false);
320+ assertFormulaEquals('="abc" < "xyz"', true);
321+ assertFormulaEquals('="abc" <= "abc"', true);
322+ assertFormulaEquals('="abc" <= "xyz"', true);
323+ assertFormulaEquals('="xyz" <= "abc"', false);
324+ assertFormulaEquals('="abc" >= "abc"', true);
325+ assertFormulaEquals('="abc" >= "zyx"', false);
326+ assertFormulaEquals('="xyz" >= "abc"', true);
327+ assertFormulaEquals('="abc" <> "abc"', false);
328+ assertFormulaEquals('="abc" <> "zyz"', true);
329+});
330+
331+test("Sheet, parse comparison operators on boolean", function(){
332+ assertFormulaEquals('=TRUE = TRUE', true);
333+ assertFormulaEquals('=TRUE = FALSE', false);
334+ assertFormulaEquals('=FALSE = FALSE', true);
335+ assertFormulaEquals('=TRUE > TRUE', false);
336+ assertFormulaEquals('=TRUE > FALSE', true);
337+ assertFormulaEquals('=FALSE > FALSE', false);
338+ assertFormulaEquals('=TRUE <= TRUE', true);
339+ assertFormulaEquals('=TRUE <= FALSE', false);
340+ assertFormulaEquals('=FALSE <= TRUE', true);
341+ assertFormulaEquals('=TRUE >= TRUE', true);
342+ assertFormulaEquals('=TRUE >= FALSE', true);
343+ assertFormulaEquals('=FALSE >= TRUE', false);
344+ assertFormulaEquals('=TRUE <> TRUE', false);
345+ assertFormulaEquals('=FALSE <> FALSE', false);
346+ assertFormulaEquals('=TRUE <> FALSE', true);
347+ assertFormulaEquals('=FALSE <> TRUE', true);
348+});
349+
350+test("Sheet, parse operators, order of operations", function(){
351+ assertFormulaEquals('=10 + -10', 0);
352+ assertFormulaEquals('=10 + -10 = 0', true);
353+ assertFormulaEquals('=10 + -10 = 0 & "str"', false);
354+ assertFormulaEquals('=-10%', -0.1);
355+ assertFormulaEquals('=10 + 10%', 10.1);
356+ assertFormulaEquals('=-10 + 10%', -9.9);
357+ assertFormulaEquals('=-10 - +10%', -10.1);
358+ assertFormulaEquals('=2^-10 + 10%', 0.1009765625);
359+ assertFormulaEquals('=4 * 5 / 2', 10);
360+ assertFormulaEquals('=4 / 5 * 4', 3.2);
361+ assertFormulaEquals('=2^2*5', 20);
362+ assertFormulaEquals('=2^(2*5)', 1024);
363+});
364+
365+test("Sheet, parse and throw error literal", function () {
366+ assertFormulaEqualsError('=#N/A', NA_ERROR);
367+ assertFormulaEqualsError('=#NUM!', NUM_ERROR);
368+ assertFormulaEqualsError('=#REF!', REF_ERROR);
369+ assertFormulaEqualsError('=#NULL!', NULL_ERROR);
370+ assertFormulaEqualsError('=#ERROR', PARSE_ERROR);
371+ assertFormulaEqualsError('=#DIV/0!', DIV_ZERO_ERROR);
372+ assertFormulaEqualsError('=#VALUE!', VALUE_ERROR);
373+});
374+
375+test("Sheet, parse plain numbers", function() {
376+ assertFormulaEquals('=10', 10);
377+ // assertEquals(parser.parse('.1'), 0.1); // TODO: Fails because our parser doesn't expect a decimal right away.
378+ assertFormulaEquals('=+1', 1);
379+ assertFormulaEquals('=-1', -1);
380+ assertFormulaEquals('=++1', 1);
381+ assertFormulaEquals('=--1', 1);
382+ assertFormulaEquals('=10e1', 100);
383+ assertFormulaEquals('=0e1', 0);
384+ // assertEquals(parser.parse('0.e1'), 0); // TODO: Fails. After decimal, finds 'e' and thinks it's a variable.
385+ assertFormulaEquals('=-10e1', -100);
386+ assertFormulaEquals('=+10e1', 100);
387+ assertFormulaEquals('=++10e1', 100);
388+ assertFormulaEquals('=--10e1', 100);
389+});
390+
391+test("Sheet, parse complex numbers and math", function(){
392+ assertFormulaEquals('="10" + 10', 20);
393+ assertFormulaEquals('="10.111111" + 0', 10.111111);
394+ assertFormulaEquals('=10%', 0.1);
395+ assertFormulaEquals('=10% + 1', 1.1);
396+ assertFormulaEquals('="10e1" + 0', 100);
397+ assertFormulaEquals('=10e1', 100);
398+ assertFormulaEquals('=10e-1', 1);
399+ assertFormulaEquals('=10e+1', 100);
400+ assertFormulaEquals('=10E1', 100);
401+ assertFormulaEquals('=10E-1', 1);
402+ assertFormulaEquals('=10E+1', 100);
403+ assertFormulaEquals('="1,000,000" + 0', 1000000);
404+ assertFormulaEquals('="+$10.00" + 0', 10);
405+ assertFormulaEquals('="-$10.00" + 0', -10);
406+ assertFormulaEquals('="$+10.00" + 0', 10);
407+ assertFormulaEquals('="$-10.00" + 0', -10);
408+ assertFormulaEquals('="10" + 10', 20);
409+ assertFormulaEquals('="10.111111" + 0', 10.111111);
410+ assertFormulaEquals('=10%', 0.1);
411+ assertFormulaEquals('=10% + 1', 1.1);
412+ assertFormulaEquals('="10e1" + 0', 100);
413+ assertFormulaEquals('=10e1', 100);
414+ assertFormulaEquals('=10e-1', 1);
415+ assertFormulaEquals('=10e+1', 100);
416+ assertFormulaEquals('=10E1', 100);
417+ assertFormulaEquals('=10E-1', 1);
418+ assertFormulaEquals('=10E+1', 100);
419+ assertFormulaEquals('="1,000,000" + 0', 1000000);
420+ assertFormulaEqualsError('="10e" + 10', VALUE_ERROR);
421+ assertFormulaEquals('="+$10.00" + 0', 10);
422+ assertFormulaEquals('="-$10.00" + 0', -10);
423+ assertFormulaEquals('="$+10.00" + 0', 10);
424+ assertFormulaEquals('="$-10.00" + 0', -10);
425+});
426+
427+test("Sheet, parse strings", function(){
428+ assertFormulaEquals('="str"', "str");
429+ assertFormulaEquals('="str"&"str"', "strstr");
430+ assertFormulaEqualsError('="str"+"str"', VALUE_ERROR);
431+ // assertEquals("='str'", PARSE_ERROR); // TODO: Parses, but we should not allow single-quote strings.
432+});
433+
434+test("Sheet, parse boolean literals", function(){
435+ assertFormulaEquals('=TRUE', true);
436+ assertFormulaEquals('=true', true);
437+ assertFormulaEquals('=FALSE', false);
438+ assertFormulaEquals('=false', false);
439+});
440+
441+test("Sheet, parse comparison logic inside parentheses", function(){
442+ // assertEquals(parser.parse('(1=1)'), true); // TODO: Fails because we compute the value, rather than checking equality
443+ // assertEquals(parser.parse('(1=2)'), false); // TODO: Fails because we compute the value, rather than checking equality
444+ assertFormulaEquals('=(1=1)+2', 3);
445+});
446+
447+
448+test("Sheet, parse range literal", function(){
449+ // assertEqualsArray('=[1, 2, 3]', [1, 2, 3]); // TODO: Fails because we've not implemented array-level parsing.
450+ // assertEqualsArray('=[]', []);
451+ // assertEqualsArray('=["str", "str"]', ["str", "str"]);
452+ // assertEqualsArray('=["str", [1, 2, 3], [1]]', ["str", [1, 2, 3], [1]]);
453+});
454diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
455index df5b50d..1e9878a 100644
456--- a/tests/SheetFormulaTest.ts
457+++ b/tests/SheetFormulaTest.ts
458@@ -11,8 +11,6 @@ import {
459 test
460 } from "./Utils/Asserts";
461 import {
462- DIV_ZERO_ERROR,
463- VALUE_ERROR,
464 NA_ERROR,
465 PARSE_ERROR,
466 REF_ERROR
467diff --git a/tests/SheetTest.ts b/tests/SheetTest.ts
468index baf08a1..d8e0c61 100644
469--- a/tests/SheetTest.ts
470+++ b/tests/SheetTest.ts
471@@ -13,10 +13,9 @@ import {
472 } from "../src/Errors";
473
474 test("Sheet.setCell, Sheet.getCell", function(){
475- // Test setCell, getCell, valid
476- var sheet = new Sheet();
477- sheet.setCell("A2", "22");
478- var cell = sheet.getCell("A2");
479+ let s = new Sheet();
480+ s.setCell("A2", "22");
481+ let cell = s.getCell("A2");
482 assertEquals(null, cell.getFormula());
483 assertEquals("22", cell.getValue());
484 assertEquals("A2", cell.getId());
485@@ -25,21 +24,19 @@ test("Sheet.setCell, Sheet.getCell", function(){
486 assertIsNull(cell.getError());
487 assertArrayEquals([], cell.getDependencies());
488
489- // Test getCell, blank cell value
490- var blankCell = sheet.getCell("N1");
491+ let blankCell = s.getCell("N1");
492 assertEquals(true, blankCell.isBlank());
493 assertIsNull(blankCell.getError());
494 assertEquals(false, blankCell.hasFormula());
495
496- // Test setCell, with formula
497- var sheet = new Sheet();
498- var SUM_FORM = "=SUM(A1:A4)";
499- sheet.setCell("A1", "1");
500- sheet.setCell("A2", "20");
501- sheet.setCell("A3", "3.4");
502- sheet.setCell("A4", "45");
503- sheet.setCell("A5", "=SUM(A1:A4)");
504- var A5 = sheet.getCell("A5");
505+ s = new Sheet();
506+ let SUM_FORM = "=SUM(A1:A4)";
507+ s.setCell("A1", "1");
508+ s.setCell("A2", "20");
509+ s.setCell("A3", "3.4");
510+ s.setCell("A4", "45");
511+ s.setCell("A5", "=SUM(A1:A4)");
512+ let A5 = s.getCell("A5");
513 assertEquals(69.4, A5.getValue());
514 assertEquals(SUM_FORM.substr(1), A5.getFormula());
515 assertIsNull(cell.getError());
516@@ -47,45 +44,45 @@ test("Sheet.setCell, Sheet.getCell", function(){
517 });
518
519 test("Sheet.load", function(){
520- var sheet = new Sheet();
521- var SUM_FORMULA = "=SUM(A1:D1, H1)";
522- var MAX_FORMULA = "=MAX(A2:J2)";
523- var MIN_FORMULA = "=MIN(A3:J3)";
524- var AVERAGE_FORMULA = "=AVERAGE(A4:J4)";
525- var SUM_IF_FORMULA = "=SUMIF(A5:J5,5)";
526- var SUM_REF_FORMULA = "=SUM(K1, K2, K3, K4)";
527+ let sheet = new Sheet();
528+ let SUM_FORMULA = "=SUM(A1:D1, H1)";
529+ let MAX_FORMULA = "=MAX(A2:J2)";
530+ let MIN_FORMULA = "=MIN(A3:J3)";
531+ let AVERAGE_FORMULA = "=AVERAGE(A4:J4)";
532+ let SUM_IF_FORMULA = "=SUMIF(A5:J5,5)";
533+ let SUM_REF_FORMULA = "=SUM(K1, K2, K3, K4)";
534 sheet.load([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, SUM_FORMULA],
535 [-1, -10, 2, 4, 100, 1, 50, 20, 200, -100, MAX_FORMULA],
536 [-1, -40, -53, 1, 10, 30, 10, 301, -1, -20, MIN_FORMULA],
537 [20, 50, 100, 20, 1, 5, 15, 25, 45, 23, AVERAGE_FORMULA],
538 [0, 10, 1, 10, 2, 10, 3, 10, 4, 10, SUM_IF_FORMULA],
539 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SUM_REF_FORMULA]]);
540- var K1 = sheet.getCell("K1");
541+ let K1 = sheet.getCell("K1");
542 assertEquals(18, K1.getValue());
543 assertEquals(SUM_FORMULA.substr(1), K1.getFormula());
544 assertIsNull(K1.getError());
545 assertArrayEquals(['A1', 'B1', 'C1', 'D1', 'H1'], K1.getDependencies());
546- var K2 = sheet.getCell("K2");
547+ let K2 = sheet.getCell("K2");
548 assertEquals(200, K2.getValue());
549 assertEquals(MAX_FORMULA.substr(1), K2.getFormula());
550 assertIsNull(K2.getError());
551 assertArrayEquals(['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'], K2.getDependencies());
552- var K3 = sheet.getCell("K3");
553+ let K3 = sheet.getCell("K3");
554 assertEquals(-53, K3.getValue());
555 assertEquals(MIN_FORMULA.substr(1), K3.getFormula());
556 assertIsNull(K3.getError());
557 assertArrayEquals(['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'], K3.getDependencies());
558- var K4 = sheet.getCell("K4");
559+ let K4 = sheet.getCell("K4");
560 assertEquals(30.4, K4.getValue());
561 assertEquals(AVERAGE_FORMULA.substr(1), K4.getFormula());
562 assertIsNull(K4.getError());
563 assertArrayEquals(['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'], K4.getDependencies());
564- var K5 = sheet.getCell("K5");
565+ let K5 = sheet.getCell("K5");
566 assertEquals(0, K5.getValue());
567 assertEquals(SUM_IF_FORMULA.substr(1), K5.getFormula());
568 assertIsNull(K5.getError());
569 assertArrayEquals(['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'], K5.getDependencies());
570- var K6 = sheet.getCell("K6");
571+ let K6 = sheet.getCell("K6");
572 assertEquals(195.4, K6.getValue());
573 assertEquals(SUM_REF_FORMULA.substr(1), K6.getFormula());
574 assertIsNull(K6.getError());
575@@ -93,50 +90,49 @@ test("Sheet.load", function(){
576 });
577
578 test("Sheet REF error", function(){
579- var sheet = new Sheet();
580+ let sheet = new Sheet();
581 sheet.setCell("A1", "200");
582 sheet.setCell("A2", "200");
583 sheet.setCell("A3", "=SUM(A1, A2)");
584 sheet.setCell("B1", "=SUM(A3, B2)");
585 sheet.setCell("B2", "=SUM(A1, B1)");
586- var B1 = sheet.getCell("B1");
587+ let B1 = sheet.getCell("B1");
588 assertIsNull(B1.getValue());
589 assertEquals(REF_ERROR, B1.getError().name);
590 assertArrayEquals(['A3', 'B2'], B1.getDependencies());
591- var B2 = sheet.getCell("B2");
592+ let B2 = sheet.getCell("B2");
593 assertIsNull(B2.getValue());
594 assertEquals(REF_ERROR, B2.getError().name);
595 assertArrayEquals(['A1', 'B1'], B2.getDependencies());
596 });
597
598 test("Sheet cell NAME error", function(){
599- var sheet = new Sheet();
600+ let sheet = new Sheet();
601 sheet.setCell("A1", "1");
602 sheet.setCell("A2", "=SUM(A1, NN)");
603- var A2 = sheet.getCell("A2");
604+ let A2 = sheet.getCell("A2");
605 assertIsNull(A2.getValue());
606 assertEquals(NAME_ERROR, A2.getError().name);
607 assertArrayEquals(['A1'], A2.getDependencies());
608 });
609
610 test("Sheet unsupported formula NAME error", function(){
611- var sheet = new Sheet();
612+ let sheet = new Sheet();
613 sheet.setCell("A1", "1");
614 sheet.setCell("A2", "=BEN(A1)");
615- var A2 = sheet.getCell("A2");
616+ let A2 = sheet.getCell("A2");
617 assertIsNull(A2.getValue());
618 assertEquals(NAME_ERROR, A2.getError().name);
619 assertArrayEquals(['A1'], A2.getDependencies());
620 });
621
622 test("Sheet nested formulas", function(){
623-// Test nested formulas
624- var sheet = new Sheet();
625+ let sheet = new Sheet();
626 sheet.setCell("A1", "1");
627 sheet.setCell("A2", "10");
628 sheet.setCell("A3", "44.4");
629 sheet.setCell("A4", "=SUM(A1:A3, MAX(A1, A3))");
630- var A4 = sheet.getCell("A4");
631+ let A4 = sheet.getCell("A4");
632 assertEquals(99.8, A4.getValue());
633 assertEquals("SUM(A1:A3, MAX(A1, A3))", A4.getFormula());
634 assertIsNull(A4.getError());
635@@ -144,22 +140,22 @@ test("Sheet nested formulas", function(){
636 });
637
638 test("Sheet cell range query", function(){
639- var sheet = new Sheet();
640+ let sheet = new Sheet();
641 sheet.setCell("A1", "1");
642 sheet.setCell("A2", "1");
643 sheet.setCell("A3", "1");
644 sheet.setCell("A4", "1");
645 sheet.setCell("A5", "1");
646 sheet.setCell("N1", "=SUM(A1:A7)");
647- var N1 = sheet.getCell("N1");
648+ let N1 = sheet.getCell("N1");
649 assertArrayEquals(['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7'], N1.getDependencies());
650 });
651
652 test("Sheet dependency calculation propagation", function(){
653- var sheet = new Sheet();
654+ let sheet = new Sheet();
655 sheet.setCell("A1", "1");
656 sheet.setCell("A2", "=SUM(A1, 100)");
657- var A2 = sheet.getCell("A2");
658+ let A2 = sheet.getCell("A2");
659 assertEquals(101, A2.getValue());
660 assertArrayEquals(['A1'], A2.getDependencies());
661 sheet.setCell("A1", "2");
662@@ -168,10 +164,10 @@ test("Sheet dependency calculation propagation", function(){
663 });
664
665 test("Sheet cell formula update", function(){
666- var sheet = new Sheet();
667+ let sheet = new Sheet();
668 sheet.setCell("A1", "1");
669 sheet.setCell("A2", "=SUM(A1, 100)");
670- var A2 = sheet.getCell("A2");
671+ let A2 = sheet.getCell("A2");
672 assertEquals(101, A2.getValue());
673 assertArrayEquals(['A1'], A2.getDependencies());
674 sheet.setCell("A2", "=MAX(A1, 100)");