name:
src/test/js/execution/ExecutorUnaryPercentTest.ts
-rw-r--r--
2334
1import { ParseException } from "../../../main/js/errors/ParseException";
2import { runner, describe, it } from "../testutils/TestUtils";
3
4describe("Executor.execute - Unary Percent", function () {
5 it("should work with number", function () {
6 runner().addCell("Alpha", "A1", "= 0%").addExpectedValue("Alpha", "A1", 0.0).run();
7 runner().addCell("Alpha", "A1", "= 1%").addExpectedValue("Alpha", "A1", 0.01).run();
8 runner().addCell("Alpha", "A1", "= 10%").addExpectedValue("Alpha", "A1", 0.1).run();
9 runner().addCell("Alpha", "A1", "= 100%").addExpectedValue("Alpha", "A1", 1.0).run();
10 runner().addCell("Alpha", "A1", "= 1000%").addExpectedValue("Alpha", "A1", 10.0).run();
11 runner()
12 .addCell("Alpha", "A1", "= 0.2318937%")
13 .addExpectedValue("Alpha", "A1", 0.002318937)
14 .run();
15 runner()
16 .addCell("Alpha", "A1", "= 10.167531%")
17 .addExpectedValue("Alpha", "A1", 0.10167531)
18 .run();
19 });
20
21 it("should work with string", function () {
22 runner().addCell("Alpha", "A1", '= "1"%').addExpectedValue("Alpha", "A1", 0.01).run();
23 runner().addCell("Alpha", "A1", '= "10"%').addExpectedValue("Alpha", "A1", 0.1).run();
24 runner().addCell("Alpha", "A1", '= "100"%').addExpectedValue("Alpha", "A1", 1.0).run();
25 runner().addCell("Alpha", "A1", '= "1000"%').addExpectedValue("Alpha", "A1", 10.0).run();
26 runner()
27 .addCell("Alpha", "A1", '= "0.2318937"%')
28 .addExpectedValue("Alpha", "A1", 0.002318937)
29 .run();
30 runner()
31 .addCell("Alpha", "A1", '= "10.167531"%')
32 .addExpectedValue("Alpha", "A1", 0.10167531)
33 .run();
34 });
35
36 it("should work with boolean", function () {
37 runner().addCell("Alpha", "A1", "= TRUE%").addExpectedValue("Alpha", "A1", 0.01).run();
38 runner().addCell("Alpha", "A1", "= FALSE%").addExpectedValue("Alpha", "A1", 0.0).run();
39 });
40
41 it("should work with array literal", function () {
42 runner().addCell("Alpha", "A1", "= {1, 2, 3}%").addExpectedValue("Alpha", "A1", 0.01).run();
43 });
44
45 it("should work with multiple minus symbols", function () {
46 // TODO/HACK: Multiple percent postfixes are allowed in Excel, but not in Google Sheets. Another one for the books.
47 runner()
48 .addCell("Alpha", "A1", "= 1%%")
49 .addExpectedValue("Alpha", "A1", new ParseException())
50 .run();
51 });
52});