@@ -196,6 +196,11 @@ describe('calculateDefaultMemoryFromExpression', () => {
196196 await expect ( calculateRunDynamicMemory ( '0 / 0' , emptyContext ) ) . rejects . toThrow ( 'Calculated memory value is not a valid number: NaN.' ) ;
197197 } ) ;
198198
199+ it ( 'should throw error if result is Infinity' , async ( ) => {
200+ await expect ( calculateRunDynamicMemory ( 'Infinity' , emptyContext ) ) . rejects . toThrow ( 'Calculated memory value is not a valid number: Infinity.' ) ;
201+ await expect ( calculateRunDynamicMemory ( '-Infinity' , emptyContext ) ) . rejects . toThrow ( 'Calculated memory value is not a valid number: -Infinity.' ) ;
202+ } ) ;
203+
199204 it ( 'should throw error if result is a non-numeric (string)' , async ( ) => {
200205 await expect ( calculateRunDynamicMemory ( "'hello'" , emptyContext ) ) . rejects . toThrow ( 'Calculated memory value is not a valid number: hello.' ) ;
201206 } ) ;
@@ -215,29 +220,29 @@ describe('calculateDefaultMemoryFromExpression', () => {
215220 cache = {
216221 get : async ( expression : string ) => lruCache . get ( expression ) ,
217222 set : async ( expression : string , compilationResult : EvalFunction ) => { lruCache . add ( expression , compilationResult ) ; } ,
218- length : async ( ) => lruCache . length ( ) ,
223+ size : async ( ) => lruCache . length ( ) ,
219224 } ;
220225 } ) ;
221226
222227 it ( 'correctly works with cache passed in options' , async ( ) => {
223- expect ( await cache . length ( ) ) . toBe ( 0 ) ;
228+ expect ( await cache . size ( ) ) . toBe ( 0 ) ;
224229
225230 // First call - cache miss
226231 const result1 = await calculateRunDynamicMemory ( expr , context , { cache } ) ;
227232 expect ( result1 ) . toBe ( 8192 ) ;
228- expect ( await cache . length ( ) ) . toBe ( 1 ) ; // Expression is now cached
233+ expect ( await cache . size ( ) ) . toBe ( 1 ) ; // Expression is now cached
229234
230235 // Second call - cache hit
231236 const result2 = await calculateRunDynamicMemory ( expr , context , { cache } ) ;
232237 expect ( result2 ) . toBe ( 8192 ) ;
233- expect ( await cache . length ( ) ) . toBe ( 1 ) ; // Cache length is unchanged
238+ expect ( await cache . size ( ) ) . toBe ( 1 ) ; // Cache length is unchanged
234239 } ) ;
235240
236241 it ( 'should cache different expressions separately' , async ( ) => {
237242 const expr2 = 'input.size * 2048' ; // 10 * 2048 = 20480 -> 16384
238243 await calculateRunDynamicMemory ( expr , context , { cache } ) ;
239244 await calculateRunDynamicMemory ( expr2 , context , { cache } ) ;
240- expect ( await cache . length ( ) ) . toBe ( 2 ) ;
245+ expect ( await cache . size ( ) ) . toBe ( 2 ) ;
241246 } ) ;
242247 } ) ;
243248} ) ;
0 commit comments