name:
src/test/js/execution/ExecutorArrayLiteralTest.ts
-rw-r--r--
6788
1import { RefException } from "../../../main/js/errors/RefException";
2import { ValueException } from "../../../main/js/errors/ValueException";
3import { runner, it, describe } from "../testutils/TestUtils";
4
5describe("Executor.execute - Array Literal", function () {
6 it("should return REF error when given an empty array literal", function () {
7 runner()
8 .addCell("Alpha", "A1", "= {}")
9 .addExpectedValue("Alpha", "A1", new RefException())
10 .run();
11 });
12
13 it("should handle single value", function () {
14 runner().addCell("Alpha", "A1", "= {1}").addExpectedValue("Alpha", "A1", 1).run();
15 });
16
17 it("should handle single nested value", function () {
18 runner().addCell("Alpha", "A1", "= {{{{{{1}}}}}}").addExpectedValue("Alpha", "A1", 1).run();
19 });
20
21 it("should handle column-wise projection where it projects to next columns", function () {
22 runner()
23 .addCell("Alpha", "A1", "= {1, 2, 3, 4}")
24 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
25 .addExpectedValue("Alpha", "A1", 1)
26 .addExpectedValue("Alpha", "B1", 2)
27 .addExpectedValue("Alpha", "C1", 3)
28 .addExpectedValue("Alpha", "D1", 4)
29 .run();
30 });
31
32 it("should handle column-wise projection with nested columns", function () {
33 runner()
34 .addCell("Alpha", "A1", "= {1, {2, {3, {4}}}}")
35 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
36 .addExpectedValue("Alpha", "A1", 1)
37 .addExpectedValue("Alpha", "B1", 2)
38 .addExpectedValue("Alpha", "C1", 3)
39 .addExpectedValue("Alpha", "D1", 4)
40 .run();
41 });
42
43 it("should handle row-wise projection where it projects to next rows", function () {
44 runner()
45 .addCell("Alpha", "A1", "= {1; 2; 3; 4}")
46 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
47 .addExpectedValue("Alpha", "A1", 1)
48 .addExpectedValue("Alpha", "A2", 2)
49 .addExpectedValue("Alpha", "A3", 3)
50 .addExpectedValue("Alpha", "A4", 4)
51 .run();
52 runner()
53 .addCell("Alpha", "A1", "= {11;9;5;3;1}")
54 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
55 .addExpectedValue("Alpha", "A1", 11)
56 .addExpectedValue("Alpha", "A2", 9)
57 .addExpectedValue("Alpha", "A3", 5)
58 .addExpectedValue("Alpha", "A4", 3)
59 .addExpectedValue("Alpha", "A5", 1)
60 .run();
61 });
62
63 it("should handle row-wise projection with nested rows", function () {
64 runner()
65 .addCell("Alpha", "A1", "= {1; {2; {3; {4}}}}")
66 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
67 .addExpectedValue("Alpha", "A1", 1)
68 .addExpectedValue("Alpha", "A2", 2)
69 .addExpectedValue("Alpha", "A3", 3)
70 .addExpectedValue("Alpha", "A4", 4)
71 .run();
72 runner()
73 .addCell("Alpha", "A1", "= {1;{2;{3;4}};{5}}")
74 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
75 .addExpectedValue("Alpha", "A1", 1)
76 .addExpectedValue("Alpha", "A2", 2)
77 .addExpectedValue("Alpha", "A3", 3)
78 .addExpectedValue("Alpha", "A4", 4)
79 .addExpectedValue("Alpha", "A5", 5)
80 .run();
81 });
82
83 it("should handle multi-dimensional projection with row first", function () {
84 runner()
85 .addCell("Alpha", "A1", "= {1, 2;3, 4}")
86 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
87 .addExpectedValue("Alpha", "A1", 1)
88 .addExpectedValue("Alpha", "B1", 2)
89 .addExpectedValue("Alpha", "A2", 3)
90 .addExpectedValue("Alpha", "B2", 4)
91 .run();
92 runner()
93 .addCell("Alpha", "A1", "= {1, 2, 3;4, 5, 6}")
94 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
95 .addExpectedValue("Alpha", "A1", 1)
96 .addExpectedValue("Alpha", "B1", 2)
97 .addExpectedValue("Alpha", "C1", 3)
98 .addExpectedValue("Alpha", "A2", 4)
99 .addExpectedValue("Alpha", "B2", 5)
100 .addExpectedValue("Alpha", "C2", 6)
101 .run();
102 });
103
104 it("should handle multi-dimensional projection with column first", function () {
105 runner()
106 .addCell("Alpha", "A1", "= {{1; 2},{3; 4}}")
107 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
108 .addExpectedValue("Alpha", "A1", 1)
109 .addExpectedValue("Alpha", "B1", 3)
110 .addExpectedValue("Alpha", "A2", 2)
111 .addExpectedValue("Alpha", "B2", 4)
112 .run();
113 runner()
114 .addCell("Alpha", "A1", "= {{{}; {}},{{}; {}}}")
115 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
116 .addExpectedValue("Alpha", "A1", new RefException())
117 .addExpectedValue("Alpha", "B1", new RefException())
118 .addExpectedValue("Alpha", "A2", new RefException())
119 .addExpectedValue("Alpha", "B2", new RefException())
120 .run();
121 });
122
123 it("should handle multi-dimensional projection", function () {
124 runner()
125 .addCell(
126 "Alpha",
127 "A1",
128 "= {{{0.0, 1.0, 2.0};{0.1, 1.1, 2.1}};{{0.2, 1.2, 2.2};{0.3, 1.3, 2.3}};{{0.4, 1.4, 2.4};{0.5, 1.5, 2.5}}}"
129 )
130 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
131 .addExpectedValue("Alpha", "A1", 0)
132 .addExpectedValue("Alpha", "A2", 0.1)
133 .addExpectedValue("Alpha", "A3", 0.2)
134 .addExpectedValue("Alpha", "A4", 0.3)
135 .addExpectedValue("Alpha", "A5", 0.4)
136 .addExpectedValue("Alpha", "A6", 0.5)
137 .addExpectedValue("Alpha", "B1", 1)
138 .addExpectedValue("Alpha", "B2", 1.1)
139 .addExpectedValue("Alpha", "B3", 1.2)
140 .addExpectedValue("Alpha", "B4", 1.3)
141 .addExpectedValue("Alpha", "B5", 1.4)
142 .addExpectedValue("Alpha", "B6", 1.5)
143 .addExpectedValue("Alpha", "C1", 2)
144 .addExpectedValue("Alpha", "C2", 2.1)
145 .addExpectedValue("Alpha", "C3", 2.2)
146 .addExpectedValue("Alpha", "C4", 2.3)
147 .addExpectedValue("Alpha", "C5", 2.4)
148 .addExpectedValue("Alpha", "C6", 2.5)
149 .run();
150 });
151
152 it("should return VALUE exception when column/row count do not match", function () {
153 runner()
154 .addCell("Alpha", "A1", "= {1,2;3}")
155 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
156 .addExpectedValue("Alpha", "A1", new ValueException())
157 .run();
158 runner()
159 .addCell("Alpha", "A1", "= {1,2;3,4,5}")
160 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
161 .addExpectedValue("Alpha", "A1", new ValueException())
162 .run();
163 runner()
164 .addCell("Alpha", "A1", "= {11;9;5;3;1,2}")
165 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
166 .addExpectedValue("Alpha", "A1", new ValueException())
167 .run();
168 runner()
169 .addCell("Alpha", "A1", "= {{};{};{},{}}")
170 .addCell("Alpha", "Z99", "Setting grid size to be large enough.")
171 .addExpectedValue("Alpha", "A1", new ValueException())
172 .run();
173 });
174});