@cobol-ts/size 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -0
- package/dist/src/size.expression.grammer.d.ts +78 -0
- package/dist/src/size.expression.grammer.js +7 -0
- package/dist/src/size.expression.grammer.js.map +1 -0
- package/dist/src/storage.size.expression.canonicalise.d.ts +10 -0
- package/dist/src/storage.size.expression.canonicalise.js +114 -0
- package/dist/src/storage.size.expression.canonicalise.js.map +1 -0
- package/dist/src/storage.size.expression.canonicalise.spec.d.ts +1 -0
- package/dist/src/storage.size.expression.canonicalise.spec.js +759 -0
- package/dist/src/storage.size.expression.canonicalise.spec.js.map +1 -0
- package/dist/src/storage.size.expression.evaluate.d.ts +7 -0
- package/dist/src/storage.size.expression.evaluate.js +114 -0
- package/dist/src/storage.size.expression.evaluate.js.map +1 -0
- package/dist/src/storage.size.expression.evaluator.spec.d.ts +1 -0
- package/dist/src/storage.size.expression.evaluator.spec.js +913 -0
- package/dist/src/storage.size.expression.evaluator.spec.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,913 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const size_expression_grammer_1 = require("./size.expression.grammer");
|
|
4
|
+
const storage_size_expression_evaluate_1 = require("./storage.size.expression.evaluate");
|
|
5
|
+
// The fixed-size examples below must not resolve record data.
|
|
6
|
+
// The resolver deliberately throws if invoked by those examples.
|
|
7
|
+
const resolve = jest.fn((_path) => {
|
|
8
|
+
throw new Error("Fixed-size expressions must not resolve a record path");
|
|
9
|
+
});
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
resolve.mockClear();
|
|
12
|
+
});
|
|
13
|
+
describe("constant expressions: elementary COBOL fields", () => {
|
|
14
|
+
/*
|
|
15
|
+
* 01 CHARACTER-RECORD.
|
|
16
|
+
* 05 INITIAL PIC X.
|
|
17
|
+
*
|
|
18
|
+
* One DISPLAY character = 1 byte = 8 bits.
|
|
19
|
+
*/
|
|
20
|
+
describe("CHARACTER-RECORD", () => {
|
|
21
|
+
test("evaluates the complete record as 8 bits", () => {
|
|
22
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(8, resolve)).toBe(8);
|
|
23
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/*
|
|
27
|
+
* 01 ITEM-RECORD.
|
|
28
|
+
* 05 ITEM PIC X(10).
|
|
29
|
+
*
|
|
30
|
+
* Ten DISPLAY characters = 10 bytes = 80 bits.
|
|
31
|
+
*/
|
|
32
|
+
describe("ITEM-RECORD", () => {
|
|
33
|
+
test("evaluates the complete record as 80 bits", () => {
|
|
34
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(80, resolve)).toBe(80);
|
|
35
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
test.each([0, 8, 80, 1024])("recognises %i as a valid constant size", bits => {
|
|
38
|
+
expect((0, size_expression_grammer_1.isConstantSizeExpression)(bits)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
test.each([
|
|
41
|
+
-1, 1.5, NaN, Infinity, -Infinity,
|
|
42
|
+
"80", null, undefined, {}, true,
|
|
43
|
+
])("rejects %p as a constant size", value => {
|
|
44
|
+
expect((0, size_expression_grammer_1.isConstantSizeExpression)(value)).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
/*
|
|
48
|
+
* 01 MESSAGE-RECORD.
|
|
49
|
+
* 05 MESSAGE-TEXT PIC X(128).
|
|
50
|
+
*
|
|
51
|
+
* 128 bytes = 1024 bits.
|
|
52
|
+
*/
|
|
53
|
+
describe("MESSAGE-RECORD", () => {
|
|
54
|
+
test("evaluates the complete record as 1024 bits", () => {
|
|
55
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(1024, resolve)).toBe(1024);
|
|
56
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
/*
|
|
60
|
+
* 01 STATUS-RECORD.
|
|
61
|
+
* 05 STATUS PIC X.
|
|
62
|
+
* 88 STATUS-READY VALUE "R".
|
|
63
|
+
*
|
|
64
|
+
* STATUS occupies 8 bits. The level-88 condition allocates no additional
|
|
65
|
+
* storage, so the entire record is 8 bits, not zero.
|
|
66
|
+
*/
|
|
67
|
+
describe("STATUS-RECORD (level 88 condition)", () => {
|
|
68
|
+
test("counts the underlying field, but not the condition name", () => {
|
|
69
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(8, resolve)).toBe(8);
|
|
70
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("sum expressions: consecutive COBOL fields and groups", () => {
|
|
75
|
+
/*
|
|
76
|
+
* 01 CUSTOMER-RECORD.
|
|
77
|
+
* 05 CUSTOMER-AGE PIC 99.
|
|
78
|
+
* 05 CUSTOMER-NAME PIC X(30).
|
|
79
|
+
* 05 CUSTOMER-POSTCODE PIC X(8).
|
|
80
|
+
*
|
|
81
|
+
* DISPLAY storage: 2 + 30 + 8 = 40 bytes = 320 bits.
|
|
82
|
+
*/
|
|
83
|
+
describe("CUSTOMER-RECORD (flat)", () => {
|
|
84
|
+
test("adds the sizes of three consecutive fields", () => {
|
|
85
|
+
const expression = {
|
|
86
|
+
kind: "sum",
|
|
87
|
+
terms: [16, 240, 64],
|
|
88
|
+
};
|
|
89
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(320);
|
|
90
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
/*
|
|
94
|
+
* 01 CUSTOMER-RECORD.
|
|
95
|
+
* 05 CUSTOMER-AGE PIC 99.
|
|
96
|
+
* 05 CUSTOMER-NAME PIC X(30).
|
|
97
|
+
* 05 ADDRESS-DETAILS.
|
|
98
|
+
* 10 HOUSE-NUMBER PIC 9(4).
|
|
99
|
+
* 10 STREET-NAME PIC X(25).
|
|
100
|
+
* 10 POSTCODE PIC X(8).
|
|
101
|
+
*
|
|
102
|
+
* ADDRESS-DETAILS is a group, not an extra stored field.
|
|
103
|
+
* 2 + 30 + (4 + 25 + 8) = 69 bytes = 552 bits.
|
|
104
|
+
*/
|
|
105
|
+
describe("CUSTOMER-RECORD (nested address)", () => {
|
|
106
|
+
test("recursively sums the address fields into the record", () => {
|
|
107
|
+
const expression = {
|
|
108
|
+
kind: "sum",
|
|
109
|
+
terms: [
|
|
110
|
+
16,
|
|
111
|
+
240,
|
|
112
|
+
{
|
|
113
|
+
kind: "sum",
|
|
114
|
+
terms: [32, 200, 64],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(552);
|
|
119
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
/*
|
|
123
|
+
* 01 CUSTOMER-RECORD.
|
|
124
|
+
* 05 CUSTOMER-NAME PIC X(30).
|
|
125
|
+
* 05 CONTACT-DETAILS.
|
|
126
|
+
* 10 HOME-ADDRESS.
|
|
127
|
+
* 15 HOUSE-NUMBER PIC 9(4).
|
|
128
|
+
* 15 POSTCODE PIC X(8).
|
|
129
|
+
* 10 PHONE PIC X(12).
|
|
130
|
+
*
|
|
131
|
+
* Two group levels: 30 + ((4 + 8) + 12) = 54 bytes = 432 bits.
|
|
132
|
+
*/
|
|
133
|
+
describe("CUSTOMER-RECORD (two nested group levels)", () => {
|
|
134
|
+
test("evaluates sums nested within sums", () => {
|
|
135
|
+
const expression = {
|
|
136
|
+
kind: "sum",
|
|
137
|
+
terms: [
|
|
138
|
+
240,
|
|
139
|
+
{
|
|
140
|
+
kind: "sum",
|
|
141
|
+
terms: [
|
|
142
|
+
{ kind: "sum", terms: [32, 64] },
|
|
143
|
+
96,
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(432);
|
|
149
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe("occurs expressions: fixed-count COBOL tables", () => {
|
|
154
|
+
/*
|
|
155
|
+
* 01 CODE-RECORD.
|
|
156
|
+
* 05 CODES OCCURS 5 TIMES.
|
|
157
|
+
* 10 CODE PIC X(4).
|
|
158
|
+
*
|
|
159
|
+
* Five occurrences of four characters: 5 × 4 = 20 bytes = 160 bits.
|
|
160
|
+
*/
|
|
161
|
+
describe("CODE-RECORD (simple OCCURS)", () => {
|
|
162
|
+
test("sums the sizes of its fixed-size occurrences", () => {
|
|
163
|
+
const expression = {
|
|
164
|
+
kind: "occurs",
|
|
165
|
+
count: 5,
|
|
166
|
+
expression: 32,
|
|
167
|
+
};
|
|
168
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(160);
|
|
169
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
/*
|
|
173
|
+
* 01 CUSTOMER-RECORD.
|
|
174
|
+
* 05 CUSTOMER-NAME PIC X(30).
|
|
175
|
+
* 05 POSTCODES OCCURS 3 TIMES.
|
|
176
|
+
* 10 POSTCODE PIC X(8).
|
|
177
|
+
*
|
|
178
|
+
* 30 + (3 × 8) = 54 bytes = 432 bits.
|
|
179
|
+
*/
|
|
180
|
+
describe("CUSTOMER-RECORD (fields followed by OCCURS)", () => {
|
|
181
|
+
test("adds a fixed table to ordinary fields", () => {
|
|
182
|
+
const expression = {
|
|
183
|
+
kind: "sum",
|
|
184
|
+
terms: [
|
|
185
|
+
240,
|
|
186
|
+
{ kind: "occurs", count: 3, expression: 64 },
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(432);
|
|
190
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
/*
|
|
194
|
+
* 01 CUSTOMER-RECORD.
|
|
195
|
+
* 05 CUSTOMER-NAME PIC X(30).
|
|
196
|
+
* 05 ADDRESSES OCCURS 2 TIMES.
|
|
197
|
+
* 10 HOUSE-NUMBER PIC 9(4).
|
|
198
|
+
* 10 STREET-NAME PIC X(25).
|
|
199
|
+
* 10 POSTCODE PIC X(8).
|
|
200
|
+
*
|
|
201
|
+
* 30 + 2 × (4 + 25 + 8) = 104 bytes = 832 bits.
|
|
202
|
+
*/
|
|
203
|
+
describe("CUSTOMER-RECORD (OCCURS of a group)", () => {
|
|
204
|
+
test("sums a nested group for each address", () => {
|
|
205
|
+
const expression = {
|
|
206
|
+
kind: "sum",
|
|
207
|
+
terms: [
|
|
208
|
+
240,
|
|
209
|
+
{
|
|
210
|
+
kind: "occurs",
|
|
211
|
+
count: 2,
|
|
212
|
+
expression: {
|
|
213
|
+
kind: "sum",
|
|
214
|
+
terms: [32, 200, 64],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(832);
|
|
220
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
/*
|
|
224
|
+
* 01 WAREHOUSE-RECORD.
|
|
225
|
+
* 05 SHELVES OCCURS 2 TIMES.
|
|
226
|
+
* 10 BINS OCCURS 3 TIMES.
|
|
227
|
+
* 15 BIN-CODE PIC X(4).
|
|
228
|
+
* 15 QUANTITY PIC 9(3).
|
|
229
|
+
*
|
|
230
|
+
* 2 × (3 × (4 + 3)) = 42 bytes = 336 bits.
|
|
231
|
+
*/
|
|
232
|
+
describe("WAREHOUSE-RECORD (nested fixed OCCURS)", () => {
|
|
233
|
+
test("evaluates nested repetitions and a nested group", () => {
|
|
234
|
+
const expression = {
|
|
235
|
+
kind: "occurs",
|
|
236
|
+
count: 2,
|
|
237
|
+
expression: {
|
|
238
|
+
kind: "occurs",
|
|
239
|
+
count: 3,
|
|
240
|
+
expression: {
|
|
241
|
+
kind: "sum",
|
|
242
|
+
terms: [32, 24],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(336);
|
|
247
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe("redefines expressions: overlapping COBOL storage", () => {
|
|
252
|
+
/*
|
|
253
|
+
* 01 MESSAGE-RECORD.
|
|
254
|
+
* 05 RAW-MESSAGE PIC X(8).
|
|
255
|
+
* 05 DECODED-MESSAGE REDEFINES RAW-MESSAGE.
|
|
256
|
+
* 10 MESSAGE-TYPE PIC X(2).
|
|
257
|
+
* 10 MESSAGE-ID PIC 9(6).
|
|
258
|
+
*
|
|
259
|
+
* Both views occupy the same 8 bytes. REDEFINES does not add
|
|
260
|
+
* another 8 bytes: max(8, 2 + 6) = 8 bytes = 64 bits.
|
|
261
|
+
*/
|
|
262
|
+
describe("MESSAGE-RECORD (simple REDEFINES)", () => {
|
|
263
|
+
test("uses the largest view rather than summing the views", () => {
|
|
264
|
+
const expression = {
|
|
265
|
+
kind: "max",
|
|
266
|
+
terms: [
|
|
267
|
+
64,
|
|
268
|
+
{ kind: "sum", terms: [16, 48] },
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(64);
|
|
272
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
/*
|
|
276
|
+
* 01 CUSTOMER-RECORD.
|
|
277
|
+
* 05 CUSTOMER-ID PIC X(4).
|
|
278
|
+
* 05 CONTACT-DATA.
|
|
279
|
+
* 10 PHONE PIC X(12).
|
|
280
|
+
* 05 SHORT-CONTACT REDEFINES CONTACT-DATA.
|
|
281
|
+
* 10 AREA-CODE PIC X(4).
|
|
282
|
+
* 10 LOCAL-CODE PIC X(4).
|
|
283
|
+
* 05 ACTIVE-FLAG PIC X.
|
|
284
|
+
*
|
|
285
|
+
* CONTACT-DATA occupies 12 bytes; SHORT-CONTACT views only its
|
|
286
|
+
* first 8 bytes. Its shorter view does not shrink the reserved
|
|
287
|
+
* storage. Total: 4 + max(12, 4 + 4) + 1 = 17 bytes = 136 bits.
|
|
288
|
+
*/
|
|
289
|
+
describe("CUSTOMER-RECORD (shorter redefinition)", () => {
|
|
290
|
+
test("reserves the maximum overlay extent and counts following fields", () => {
|
|
291
|
+
const expression = {
|
|
292
|
+
kind: "sum",
|
|
293
|
+
terms: [
|
|
294
|
+
32,
|
|
295
|
+
{
|
|
296
|
+
kind: "max",
|
|
297
|
+
terms: [96, { kind: "sum", terms: [32, 32] }],
|
|
298
|
+
},
|
|
299
|
+
8,
|
|
300
|
+
],
|
|
301
|
+
};
|
|
302
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(136);
|
|
303
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
/*
|
|
307
|
+
* 01 SALES-RECORD.
|
|
308
|
+
* 05 SALES-HEADER PIC X(3).
|
|
309
|
+
* 05 LINE-DATA PIC X(12).
|
|
310
|
+
* 05 ITEM-LINES REDEFINES LINE-DATA.
|
|
311
|
+
* 10 ITEMS OCCURS 3 TIMES.
|
|
312
|
+
* 15 ITEM-CODE PIC X(2).
|
|
313
|
+
* 15 QUANTITY PIC 9(2).
|
|
314
|
+
* 05 TRAILER PIC X(2).
|
|
315
|
+
*
|
|
316
|
+
* The table of three 4-byte items reuses the 12-byte LINE-DATA
|
|
317
|
+
* region. Total: 3 + max(12, 3 × (2 + 2)) + 2 = 17 bytes = 136 bits.
|
|
318
|
+
*/
|
|
319
|
+
describe("SALES-RECORD (REDEFINES with OCCURS)", () => {
|
|
320
|
+
test("combines an overlay, a repeated group and following fields", () => {
|
|
321
|
+
const expression = {
|
|
322
|
+
kind: "sum",
|
|
323
|
+
terms: [
|
|
324
|
+
24,
|
|
325
|
+
{
|
|
326
|
+
kind: "max",
|
|
327
|
+
terms: [
|
|
328
|
+
96,
|
|
329
|
+
{
|
|
330
|
+
kind: "occurs",
|
|
331
|
+
count: 3,
|
|
332
|
+
expression: { kind: "sum", terms: [16, 16] },
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
16,
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(136);
|
|
340
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
/*
|
|
344
|
+
* 01 DELIVERY-RECORD.
|
|
345
|
+
* 05 ROUTE-CODE PIC X(2).
|
|
346
|
+
* 05 PARCELS OCCURS 2 TIMES.
|
|
347
|
+
* 10 PARCEL-ID PIC X(4).
|
|
348
|
+
* 10 ADDRESS-DATA.
|
|
349
|
+
* 15 RAW-ADDRESS PIC X(10).
|
|
350
|
+
* 15 STRUCTURED-ADDRESS REDEFINES RAW-ADDRESS.
|
|
351
|
+
* 20 STREET PIC X(6).
|
|
352
|
+
* 20 POSTCODE PIC X(4).
|
|
353
|
+
* 10 STATUS PIC X.
|
|
354
|
+
*
|
|
355
|
+
* Each parcel occupies 4 + max(10, 6 + 4) + 1 = 15 bytes.
|
|
356
|
+
* Total: 2 + 2 × 15 = 32 bytes = 256 bits.
|
|
357
|
+
*
|
|
358
|
+
* The redefinition is nested inside ADDRESS-DATA, which is
|
|
359
|
+
* itself inside a fixed OCCURS table.
|
|
360
|
+
*/
|
|
361
|
+
describe("DELIVERY-RECORD (nested REDEFINES inside OCCURS)", () => {
|
|
362
|
+
test("evaluates a nested overlay for every repeated group", () => {
|
|
363
|
+
const expression = {
|
|
364
|
+
kind: "sum",
|
|
365
|
+
terms: [
|
|
366
|
+
16,
|
|
367
|
+
{
|
|
368
|
+
kind: "occurs",
|
|
369
|
+
count: 2,
|
|
370
|
+
expression: {
|
|
371
|
+
kind: "sum",
|
|
372
|
+
terms: [
|
|
373
|
+
32,
|
|
374
|
+
{
|
|
375
|
+
kind: "sum",
|
|
376
|
+
terms: [{
|
|
377
|
+
kind: "max",
|
|
378
|
+
terms: [
|
|
379
|
+
80,
|
|
380
|
+
{ kind: "sum", terms: [48, 32] },
|
|
381
|
+
],
|
|
382
|
+
}],
|
|
383
|
+
},
|
|
384
|
+
8,
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
};
|
|
390
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(256);
|
|
391
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
/*
|
|
396
|
+
* 01 ORDER-RECORD.
|
|
397
|
+
* 05 ITEM-COUNT PIC 9.
|
|
398
|
+
* 05 ITEMS OCCURS 0 TO 9 TIMES
|
|
399
|
+
* DEPENDING ON ITEM-COUNT.
|
|
400
|
+
* 10 ITEM-CODE PIC X(10).
|
|
401
|
+
*
|
|
402
|
+
* One byte for ITEM-COUNT; 10 bytes per item.
|
|
403
|
+
*/
|
|
404
|
+
describe("depending-on: ORDER-RECORD (one dependent table)", () => {
|
|
405
|
+
const expression = {
|
|
406
|
+
kind: "sum",
|
|
407
|
+
terms: [
|
|
408
|
+
8,
|
|
409
|
+
{
|
|
410
|
+
kind: "depending-on",
|
|
411
|
+
path: ["ORDER-RECORD", "ITEM-COUNT"],
|
|
412
|
+
expression: 80,
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
};
|
|
416
|
+
test.each([
|
|
417
|
+
[0, 8],
|
|
418
|
+
[1, 88],
|
|
419
|
+
[3, 248],
|
|
420
|
+
[9, 728],
|
|
421
|
+
])("ITEM-COUNT = %i makes %i bits", (count, expected) => {
|
|
422
|
+
const lookup = jest.fn((_path) => count);
|
|
423
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(expected);
|
|
424
|
+
expect(lookup).toHaveBeenCalledTimes(1);
|
|
425
|
+
expect(lookup).toHaveBeenCalledWith(["ORDER-RECORD", "ITEM-COUNT"]);
|
|
426
|
+
});
|
|
427
|
+
test.each(["3", -1, 1.5, null, undefined, Infinity])("rejects invalid count %p", count => {
|
|
428
|
+
const lookup = jest.fn((_path) => count);
|
|
429
|
+
expect(() => (0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toThrow("Invalid OCCURS DEPENDING ON count");
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
/*
|
|
433
|
+
* 01 BATCH-RECORD.
|
|
434
|
+
* 05 GROUP-COUNT PIC 9.
|
|
435
|
+
* 05 GROUPS OCCURS 0 TO 9 TIMES
|
|
436
|
+
* DEPENDING ON GROUP-COUNT.
|
|
437
|
+
* 10 ITEM-COUNT PIC 9.
|
|
438
|
+
* 10 ITEMS OCCURS 0 TO 9 TIMES
|
|
439
|
+
* DEPENDING ON ITEM-COUNT.
|
|
440
|
+
* 15 ITEM PIC X(10).
|
|
441
|
+
*
|
|
442
|
+
* Example counts: GROUP-COUNT = 3; ITEM-COUNT = [2,5,1].
|
|
443
|
+
* Total = 1 + (1+20) + (1+50) + (1+10) = 84 bytes.
|
|
444
|
+
* The nested count path substitutes numeric depth 0 (the nearest enclosing group index).
|
|
445
|
+
*/
|
|
446
|
+
describe("depending-on: BATCH-RECORD (two nested dependencies)", () => {
|
|
447
|
+
const expression = {
|
|
448
|
+
kind: "sum",
|
|
449
|
+
terms: [
|
|
450
|
+
8,
|
|
451
|
+
{
|
|
452
|
+
kind: "depending-on",
|
|
453
|
+
path: ["BATCH-RECORD", "GROUP-COUNT"],
|
|
454
|
+
expression: {
|
|
455
|
+
kind: "sum",
|
|
456
|
+
terms: [
|
|
457
|
+
8,
|
|
458
|
+
{
|
|
459
|
+
kind: "depending-on",
|
|
460
|
+
path: [
|
|
461
|
+
"BATCH-RECORD", "GROUPS",
|
|
462
|
+
0, "ITEM-COUNT",
|
|
463
|
+
],
|
|
464
|
+
expression: 80,
|
|
465
|
+
},
|
|
466
|
+
],
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
};
|
|
471
|
+
test("reads a different item count for each group", () => {
|
|
472
|
+
const counts = [2, 5, 1];
|
|
473
|
+
const seen = [];
|
|
474
|
+
const lookup = jest.fn((path) => {
|
|
475
|
+
seen.push([...path]);
|
|
476
|
+
if (path.join("/") === "BATCH-RECORD/GROUP-COUNT")
|
|
477
|
+
return 3;
|
|
478
|
+
return counts[path[2]];
|
|
479
|
+
});
|
|
480
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(672);
|
|
481
|
+
expect(seen).toEqual([
|
|
482
|
+
["BATCH-RECORD", "GROUP-COUNT"],
|
|
483
|
+
["BATCH-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
484
|
+
["BATCH-RECORD", "GROUPS", 1, "ITEM-COUNT"],
|
|
485
|
+
["BATCH-RECORD", "GROUPS", 2, "ITEM-COUNT"],
|
|
486
|
+
]);
|
|
487
|
+
});
|
|
488
|
+
test("does not enter the body when there are zero groups", () => {
|
|
489
|
+
const lookup = jest.fn((path) => {
|
|
490
|
+
if (path[1] === "GROUP-COUNT")
|
|
491
|
+
return 0;
|
|
492
|
+
throw new Error("Inner body must not be evaluated");
|
|
493
|
+
});
|
|
494
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(8);
|
|
495
|
+
expect(lookup).toHaveBeenCalledTimes(1);
|
|
496
|
+
});
|
|
497
|
+
test("rejects an index that is not bound at its count path", () => {
|
|
498
|
+
const invalid = {
|
|
499
|
+
kind: "depending-on",
|
|
500
|
+
path: ["BATCH-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
501
|
+
expression: 80,
|
|
502
|
+
};
|
|
503
|
+
expect(() => (0, storage_size_expression_evaluate_1.evaluateStorageSize)(invalid, jest.fn())).toThrow("Unbound OCCURS variable at relative depth 0");
|
|
504
|
+
});
|
|
505
|
+
test("rejects a relative depth larger than the enclosing lambda stack", () => {
|
|
506
|
+
const invalid = {
|
|
507
|
+
kind: "depending-on",
|
|
508
|
+
path: ["BATCH-RECORD", "GROUP-COUNT"],
|
|
509
|
+
expression: {
|
|
510
|
+
kind: "depending-on",
|
|
511
|
+
path: [
|
|
512
|
+
"BATCH-RECORD", "GROUPS",
|
|
513
|
+
1, "ITEM-COUNT",
|
|
514
|
+
],
|
|
515
|
+
expression: 80,
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
const lookup = jest.fn((path) => {
|
|
519
|
+
if (path[1] === "GROUP-COUNT")
|
|
520
|
+
return 1;
|
|
521
|
+
throw new Error("An invalid inner path must not reach the resolver");
|
|
522
|
+
});
|
|
523
|
+
expect(() => (0, storage_size_expression_evaluate_1.evaluateStorageSize)(invalid, lookup)).toThrow("Unbound OCCURS variable at relative depth 1");
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
/*
|
|
527
|
+
* 01 DEEP-RECORD.
|
|
528
|
+
* 05 GROUP-COUNT PIC 9.
|
|
529
|
+
* 05 GROUPS OCCURS 0 TO 9 TIMES DEPENDING ON GROUP-COUNT.
|
|
530
|
+
* 10 ITEM-COUNT PIC 9.
|
|
531
|
+
* 10 ITEMS OCCURS 0 TO 9 TIMES DEPENDING ON ITEM-COUNT.
|
|
532
|
+
* 15 DETAIL-COUNT PIC 9.
|
|
533
|
+
* 15 DETAILS OCCURS 0 TO 9 TIMES DEPENDING ON DETAIL-COUNT.
|
|
534
|
+
* 20 DETAIL PIC X(4).
|
|
535
|
+
*
|
|
536
|
+
* Two groups, with items [2,1]; detail counts [[1,3],[2]].
|
|
537
|
+
* 1 + (1 + (1+4) + (1+12)) + (1 + (1+8)) = 30 bytes.
|
|
538
|
+
* Detail count references both enclosing variables: numeric depth 1 (group) and depth 0 (item).
|
|
539
|
+
*/
|
|
540
|
+
describe("depending-on: DEEP-RECORD (three nested dependencies)", () => {
|
|
541
|
+
const expression = {
|
|
542
|
+
kind: "sum",
|
|
543
|
+
terms: [8, {
|
|
544
|
+
kind: "depending-on",
|
|
545
|
+
path: ["DEEP-RECORD", "GROUP-COUNT"],
|
|
546
|
+
expression: {
|
|
547
|
+
kind: "sum",
|
|
548
|
+
terms: [8, {
|
|
549
|
+
kind: "depending-on",
|
|
550
|
+
path: ["DEEP-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
551
|
+
expression: {
|
|
552
|
+
kind: "sum",
|
|
553
|
+
terms: [8, {
|
|
554
|
+
kind: "depending-on",
|
|
555
|
+
path: [
|
|
556
|
+
"DEEP-RECORD", "GROUPS", 1,
|
|
557
|
+
"ITEMS", 0, "DETAIL-COUNT",
|
|
558
|
+
],
|
|
559
|
+
expression: 32,
|
|
560
|
+
}],
|
|
561
|
+
},
|
|
562
|
+
}],
|
|
563
|
+
},
|
|
564
|
+
}],
|
|
565
|
+
};
|
|
566
|
+
test("uses both enclosing occurrence indices", () => {
|
|
567
|
+
const detailCounts = [[1, 3], [2]];
|
|
568
|
+
const seen = [];
|
|
569
|
+
const lookup = jest.fn((path) => {
|
|
570
|
+
seen.push([...path]);
|
|
571
|
+
if (path[1] === "GROUP-COUNT")
|
|
572
|
+
return 2;
|
|
573
|
+
if (path[3] === "ITEM-COUNT")
|
|
574
|
+
return detailCounts[path[2]].length;
|
|
575
|
+
return detailCounts[path[2]][path[4]];
|
|
576
|
+
});
|
|
577
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(240);
|
|
578
|
+
expect(seen).toEqual([
|
|
579
|
+
["DEEP-RECORD", "GROUP-COUNT"],
|
|
580
|
+
["DEEP-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
581
|
+
["DEEP-RECORD", "GROUPS", 0, "ITEMS", 0, "DETAIL-COUNT"],
|
|
582
|
+
["DEEP-RECORD", "GROUPS", 0, "ITEMS", 1, "DETAIL-COUNT"],
|
|
583
|
+
["DEEP-RECORD", "GROUPS", 1, "ITEM-COUNT"],
|
|
584
|
+
["DEEP-RECORD", "GROUPS", 1, "ITEMS", 0, "DETAIL-COUNT"],
|
|
585
|
+
]);
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
/*
|
|
589
|
+
* 01 BATCH-RECORD.
|
|
590
|
+
* 05 GROUPS OCCURS 3 TIMES.
|
|
591
|
+
* 10 ITEM-COUNT PIC 9.
|
|
592
|
+
* 10 ITEMS OCCURS 0 TO 9 TIMES
|
|
593
|
+
* DEPENDING ON ITEM-COUNT.
|
|
594
|
+
* 15 ITEM PIC X(10).
|
|
595
|
+
*
|
|
596
|
+
* Fixed count does not guarantee fixed-size elements: GROUPS[0..2]
|
|
597
|
+
* have ITEM-COUNT values [2,5,1]. Their sizes are 21, 51, 11 bytes,
|
|
598
|
+
* so the entire record occupies 83 bytes = 664 bits.
|
|
599
|
+
*/
|
|
600
|
+
describe("occurs: BATCH-RECORD (fixed outer table, variable inner table)", () => {
|
|
601
|
+
const expression = {
|
|
602
|
+
kind: "occurs",
|
|
603
|
+
count: 3,
|
|
604
|
+
expression: {
|
|
605
|
+
kind: "sum",
|
|
606
|
+
terms: [
|
|
607
|
+
8,
|
|
608
|
+
{
|
|
609
|
+
kind: "depending-on",
|
|
610
|
+
path: ["BATCH-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
611
|
+
expression: 80,
|
|
612
|
+
},
|
|
613
|
+
],
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
test("reads a distinct ITEM-COUNT for each of three fixed occurrences", () => {
|
|
617
|
+
const counts = [2, 5, 1];
|
|
618
|
+
const seen = [];
|
|
619
|
+
const lookup = jest.fn((path) => {
|
|
620
|
+
seen.push([...path]);
|
|
621
|
+
return counts[path[2]];
|
|
622
|
+
});
|
|
623
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(664);
|
|
624
|
+
expect(seen).toEqual([
|
|
625
|
+
["BATCH-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
626
|
+
["BATCH-RECORD", "GROUPS", 1, "ITEM-COUNT"],
|
|
627
|
+
["BATCH-RECORD", "GROUPS", 2, "ITEM-COUNT"],
|
|
628
|
+
]);
|
|
629
|
+
});
|
|
630
|
+
test("a zero fixed count never evaluates the element body", () => {
|
|
631
|
+
const empty = {
|
|
632
|
+
...expression,
|
|
633
|
+
count: 0,
|
|
634
|
+
};
|
|
635
|
+
const lookup = jest.fn((_path) => {
|
|
636
|
+
throw new Error("No element should be evaluated");
|
|
637
|
+
});
|
|
638
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(empty, lookup)).toBe(0);
|
|
639
|
+
expect(lookup).not.toHaveBeenCalled();
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
/*
|
|
643
|
+
* 01 STORE-RECORD.
|
|
644
|
+
* 05 AISLE-COUNT PIC 9.
|
|
645
|
+
* 05 AISLES OCCURS 0 TO 9 TIMES
|
|
646
|
+
* DEPENDING ON AISLE-COUNT.
|
|
647
|
+
* 10 SHELVES OCCURS 2 TIMES.
|
|
648
|
+
* 15 PRODUCT-COUNT PIC 9.
|
|
649
|
+
* 15 PRODUCTS OCCURS 0 TO 9 TIMES
|
|
650
|
+
* DEPENDING ON PRODUCT-COUNT.
|
|
651
|
+
* 20 PRODUCT PIC X(2).
|
|
652
|
+
*
|
|
653
|
+
* AISLE-COUNT = 2. Each aisle has two shelves, with product counts
|
|
654
|
+
* [[1,2],[3,0]]. Sizes: (1+2)+(1+4)+(1+6)+(1+0) = 16 bytes,
|
|
655
|
+
* plus the initial count byte = 17 bytes = 136 bits.
|
|
656
|
+
*
|
|
657
|
+
* At PRODUCT-COUNT, depth 0 is the fixed shelf index and depth 1
|
|
658
|
+
* is the enclosing variable aisle index.
|
|
659
|
+
*/
|
|
660
|
+
describe("occurs: STORE-RECORD (mixed fixed and dependent nesting)", () => {
|
|
661
|
+
const expression = {
|
|
662
|
+
kind: "sum",
|
|
663
|
+
terms: [
|
|
664
|
+
8,
|
|
665
|
+
{
|
|
666
|
+
kind: "depending-on",
|
|
667
|
+
path: ["STORE-RECORD", "AISLE-COUNT"],
|
|
668
|
+
expression: {
|
|
669
|
+
kind: "occurs",
|
|
670
|
+
count: 2,
|
|
671
|
+
expression: {
|
|
672
|
+
kind: "sum",
|
|
673
|
+
terms: [
|
|
674
|
+
8,
|
|
675
|
+
{
|
|
676
|
+
kind: "depending-on",
|
|
677
|
+
path: ["STORE-RECORD", "AISLES", 1, "SHELVES", 0, "PRODUCT-COUNT"],
|
|
678
|
+
expression: 16,
|
|
679
|
+
},
|
|
680
|
+
],
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
],
|
|
685
|
+
};
|
|
686
|
+
test("resolves the two enclosing indices in their proper relative order", () => {
|
|
687
|
+
const counts = [[1, 2], [3, 0]];
|
|
688
|
+
const seen = [];
|
|
689
|
+
const lookup = jest.fn((path) => {
|
|
690
|
+
seen.push([...path]);
|
|
691
|
+
if (path[1] === "AISLE-COUNT")
|
|
692
|
+
return 2;
|
|
693
|
+
return counts[path[2]][path[4]];
|
|
694
|
+
});
|
|
695
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(136);
|
|
696
|
+
expect(seen).toEqual([
|
|
697
|
+
["STORE-RECORD", "AISLE-COUNT"],
|
|
698
|
+
["STORE-RECORD", "AISLES", 0, "SHELVES", 0, "PRODUCT-COUNT"],
|
|
699
|
+
["STORE-RECORD", "AISLES", 0, "SHELVES", 1, "PRODUCT-COUNT"],
|
|
700
|
+
["STORE-RECORD", "AISLES", 1, "SHELVES", 0, "PRODUCT-COUNT"],
|
|
701
|
+
["STORE-RECORD", "AISLES", 1, "SHELVES", 1, "PRODUCT-COUNT"],
|
|
702
|
+
]);
|
|
703
|
+
});
|
|
704
|
+
/*
|
|
705
|
+
* 01 ALIGNED-RECORD.
|
|
706
|
+
* 05 PREFIX PIC X.
|
|
707
|
+
* 05 AMOUNT PIC S9(9) COMP SYNC.
|
|
708
|
+
*
|
|
709
|
+
* AMOUNT requires a four-byte boundary.
|
|
710
|
+
* ALIGN returns the padding length, not the aligned position.
|
|
711
|
+
*/
|
|
712
|
+
describe("align expressions: fixed offsets", () => {
|
|
713
|
+
test.each([
|
|
714
|
+
[0, 32, 0],
|
|
715
|
+
[8, 32, 24],
|
|
716
|
+
[16, 32, 16],
|
|
717
|
+
[24, 32, 8],
|
|
718
|
+
[32, 32, 0],
|
|
719
|
+
[40, 32, 24],
|
|
720
|
+
[8, 16, 8],
|
|
721
|
+
[16, 16, 0],
|
|
722
|
+
[8, 64, 56],
|
|
723
|
+
[64, 64, 0],
|
|
724
|
+
])("align(%i, %i) evaluates to %i bits", (size, boundary, expected) => {
|
|
725
|
+
const expression = {
|
|
726
|
+
kind: "align", size, boundary
|
|
727
|
+
};
|
|
728
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(expected);
|
|
729
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
730
|
+
});
|
|
731
|
+
test("evaluates a nested sum before calculating alignment", () => {
|
|
732
|
+
const expression = {
|
|
733
|
+
kind: "align",
|
|
734
|
+
size: { kind: "sum", terms: [8, 16] },
|
|
735
|
+
boundary: 32
|
|
736
|
+
};
|
|
737
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(8);
|
|
738
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
739
|
+
});
|
|
740
|
+
});
|
|
741
|
+
/*
|
|
742
|
+
* 01 VARIABLE-RECORD.
|
|
743
|
+
* 05 ITEM-COUNT PIC 9.
|
|
744
|
+
* 05 ITEMS OCCURS 0 TO 9 TIMES DEPENDING ON ITEM-COUNT.
|
|
745
|
+
* 10 CODE PIC X(3).
|
|
746
|
+
* 05 AMOUNT PIC S9(9) COMP SYNC.
|
|
747
|
+
*
|
|
748
|
+
* The position before AMOUNT is 8 + ITEM-COUNT * 24 bits.
|
|
749
|
+
* Padding is calculated using the actual occurrence count.
|
|
750
|
+
*/
|
|
751
|
+
describe("align expressions: after ODO", () => {
|
|
752
|
+
const expression = {
|
|
753
|
+
kind: "align",
|
|
754
|
+
size: {
|
|
755
|
+
kind: "sum",
|
|
756
|
+
terms: [
|
|
757
|
+
8,
|
|
758
|
+
{
|
|
759
|
+
kind: "depending-on",
|
|
760
|
+
path: ["VARIABLE-RECORD", "ITEM-COUNT"],
|
|
761
|
+
expression: 24
|
|
762
|
+
}
|
|
763
|
+
]
|
|
764
|
+
},
|
|
765
|
+
boundary: 32
|
|
766
|
+
};
|
|
767
|
+
test.each([
|
|
768
|
+
[0, 24],
|
|
769
|
+
[1, 0],
|
|
770
|
+
[2, 8],
|
|
771
|
+
[3, 16],
|
|
772
|
+
[4, 24],
|
|
773
|
+
[5, 0],
|
|
774
|
+
])("ITEM-COUNT = %i requires %i bits of padding", (count, expected) => {
|
|
775
|
+
const lookup = jest.fn((path) => {
|
|
776
|
+
expect(path).toEqual(["VARIABLE-RECORD", "ITEM-COUNT"]);
|
|
777
|
+
return count;
|
|
778
|
+
});
|
|
779
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(expected);
|
|
780
|
+
expect(lookup).toHaveBeenCalledTimes(1);
|
|
781
|
+
});
|
|
782
|
+
test("uses alignment as an ordinary component of the record size", () => {
|
|
783
|
+
const completeRecord = {
|
|
784
|
+
kind: "sum",
|
|
785
|
+
terms: [
|
|
786
|
+
8,
|
|
787
|
+
{
|
|
788
|
+
kind: "depending-on",
|
|
789
|
+
path: ["VARIABLE-RECORD", "ITEM-COUNT"],
|
|
790
|
+
expression: 24
|
|
791
|
+
},
|
|
792
|
+
expression,
|
|
793
|
+
32
|
|
794
|
+
]
|
|
795
|
+
};
|
|
796
|
+
test.each([]); // Not required; use the assertions below.
|
|
797
|
+
for (const [count, expected] of [
|
|
798
|
+
[0, 64],
|
|
799
|
+
[1, 64],
|
|
800
|
+
[2, 96],
|
|
801
|
+
[3, 128],
|
|
802
|
+
[4, 160],
|
|
803
|
+
]) {
|
|
804
|
+
const lookup = () => count;
|
|
805
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(completeRecord, lookup)).toBe(expected);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
/*
|
|
810
|
+
* 01 GROUP-RECORD.
|
|
811
|
+
* 05 GROUPS OCCURS 3 TIMES.
|
|
812
|
+
* 10 ITEM-COUNT PIC 9.
|
|
813
|
+
* 10 ITEMS OCCURS 0 TO 9 TIMES DEPENDING ON ITEM-COUNT.
|
|
814
|
+
* 15 CODE PIC X(3).
|
|
815
|
+
* 10 AMOUNT PIC S9(9) COMP SYNC.
|
|
816
|
+
*
|
|
817
|
+
* Each GROUPS occurrence can have a different amount of padding.
|
|
818
|
+
* Alignment must use the currently bound GROUPS index.
|
|
819
|
+
*/
|
|
820
|
+
describe("align expressions: inside fixed OCCURS", () => {
|
|
821
|
+
const expression = {
|
|
822
|
+
kind: "occurs",
|
|
823
|
+
count: 3,
|
|
824
|
+
expression: {
|
|
825
|
+
kind: "align",
|
|
826
|
+
size: {
|
|
827
|
+
kind: "sum",
|
|
828
|
+
terms: [
|
|
829
|
+
8,
|
|
830
|
+
{
|
|
831
|
+
kind: "depending-on",
|
|
832
|
+
path: ["GROUP-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
833
|
+
expression: 24
|
|
834
|
+
}
|
|
835
|
+
]
|
|
836
|
+
},
|
|
837
|
+
boundary: 32
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
test("evaluates alignment independently for each occurrence", () => {
|
|
841
|
+
const counts = [0, 1, 2];
|
|
842
|
+
const seen = [];
|
|
843
|
+
const lookup = jest.fn((path) => {
|
|
844
|
+
seen.push([...path]);
|
|
845
|
+
return counts[path[2]];
|
|
846
|
+
});
|
|
847
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, lookup)).toBe(32);
|
|
848
|
+
expect(seen).toEqual([
|
|
849
|
+
["GROUP-RECORD", "GROUPS", 0, "ITEM-COUNT"],
|
|
850
|
+
["GROUP-RECORD", "GROUPS", 1, "ITEM-COUNT"],
|
|
851
|
+
["GROUP-RECORD", "GROUPS", 2, "ITEM-COUNT"]
|
|
852
|
+
]);
|
|
853
|
+
});
|
|
854
|
+
test("does not read an unvisited occurrence", () => {
|
|
855
|
+
const empty = {
|
|
856
|
+
...expression,
|
|
857
|
+
count: 0
|
|
858
|
+
};
|
|
859
|
+
const lookup = jest.fn(() => {
|
|
860
|
+
throw new Error("No occurrence should be evaluated");
|
|
861
|
+
});
|
|
862
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(empty, lookup)).toBe(0);
|
|
863
|
+
expect(lookup).not.toHaveBeenCalled();
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
/*
|
|
867
|
+
* 01 NESTED-ALIGNMENT.
|
|
868
|
+
* 05 PREFIX PIC X.
|
|
869
|
+
* 05 AMOUNT PIC S9(9) COMP SYNC.
|
|
870
|
+
*
|
|
871
|
+
* Once an offset has been padded to a boundary, another
|
|
872
|
+
* alignment operation at the same boundary requires zero padding.
|
|
873
|
+
*/
|
|
874
|
+
describe("align expressions: nested alignment", () => {
|
|
875
|
+
test("returns zero after applying the first alignment", () => {
|
|
876
|
+
const expression = {
|
|
877
|
+
kind: "align",
|
|
878
|
+
size: {
|
|
879
|
+
kind: "sum",
|
|
880
|
+
terms: [
|
|
881
|
+
8,
|
|
882
|
+
{ kind: "align", size: 8, boundary: 32 }
|
|
883
|
+
]
|
|
884
|
+
},
|
|
885
|
+
boundary: 32
|
|
886
|
+
};
|
|
887
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, resolve)).toBe(0);
|
|
888
|
+
expect(resolve).not.toHaveBeenCalled();
|
|
889
|
+
});
|
|
890
|
+
test("works when the original offset is symbolic", () => {
|
|
891
|
+
const variable = {
|
|
892
|
+
kind: "depending-on",
|
|
893
|
+
path: ["NESTED-ALIGNMENT", "COUNT"],
|
|
894
|
+
expression: 24
|
|
895
|
+
};
|
|
896
|
+
const expression = {
|
|
897
|
+
kind: "align",
|
|
898
|
+
size: {
|
|
899
|
+
kind: "sum",
|
|
900
|
+
terms: [
|
|
901
|
+
variable,
|
|
902
|
+
{ kind: "align", size: variable, boundary: 32 }
|
|
903
|
+
]
|
|
904
|
+
},
|
|
905
|
+
boundary: 32
|
|
906
|
+
};
|
|
907
|
+
for (const count of [0, 1, 2, 3, 4]) {
|
|
908
|
+
expect((0, storage_size_expression_evaluate_1.evaluateStorageSize)(expression, () => count)).toBe(0);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
});
|
|
913
|
+
//# sourceMappingURL=storage.size.expression.evaluator.spec.js.map
|