Skip to content

Commit 30dde7a

Browse files
committed
feat: 🎸 support named tuple keys in capacity estimatro
1 parent 61d77a1 commit 30dde7a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/codegen/capacity/CapacityEstimatorCodegen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ export class CapacityEstimatorCodegen {
174174
);
175175
}
176176

177+
protected genKey(r: JsExpression, type: KeyType<any, any>): void {
178+
this.onNode(r, type.val);
179+
}
180+
177181
protected onNode(value: JsExpression, type: Type): void {
178182
const kind = type.kind();
179183
switch (kind) {
@@ -203,6 +207,9 @@ export class CapacityEstimatorCodegen {
203207
case 'obj':
204208
this.genObj(value, type);
205209
break;
210+
case 'key':
211+
this.genKey(value, type as KeyType<any, any>);
212+
break;
206213
case 'map':
207214
this.genMap(value, type as MapType<any>);
208215
break;

src/codegen/capacity/__tests__/CapacityEstimatorCodegenContext.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ describe('"arr" type', () => {
135135
const estimator = CapacityEstimatorCodegen.get(type);
136136
expect(estimator([1, 'abc', 'xxxxxxxxx'])).toBe(maxEncodingCapacity([1, 'abc', 'xxxxxxxxx']));
137137
});
138+
139+
test('named tail 2-tuple', () => {
140+
const system = new ModuleType();
141+
const type = system.t.Array(t.num).tail(t.Key('very_important', t.str), t.str);
142+
const estimator = CapacityEstimatorCodegen.get(type);
143+
expect(estimator([1, 'abc', 'xxxxxxxxx'])).toBe(maxEncodingCapacity([1, 'abc', 'xxxxxxxxx']));
144+
});
138145
});
139146

140147
describe('"obj" type', () => {

0 commit comments

Comments
 (0)