@@ -256,6 +256,118 @@ describe('registry', () => {
256
256
} ) ;
257
257
} ) ;
258
258
259
+ describe ( '#withRecordFuzzer' , ( ) => {
260
+ describe ( 'on the core registry' , ( ) => {
261
+ it ( `overrides the record fuzzer max count` , ( ) => {
262
+ const b = t . record ( t . string , t . number ) ;
263
+ const r0 = lib . createCoreRegistry ( ) ;
264
+ const r = lib
265
+ . fluent ( r0 )
266
+ . withRecordFuzzer ( 3 )
267
+ . exampleGenerator ( b ) ;
268
+ for ( let i = 0 ; i < 100 ; i ++ ) {
269
+ assert . ok (
270
+ Object . getOwnPropertyNames ( r . encode ( [
271
+ i ,
272
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
273
+ ] ) as object ) . length <= 3
274
+ ) ;
275
+ }
276
+ } ) ;
277
+
278
+ it ( `does not affect unknown records` , ( ) => {
279
+ const b = t . UnknownRecord ;
280
+ const r0 = lib . createCoreRegistry ( ) ;
281
+ const r = lib
282
+ . fluent ( r0 )
283
+ . withRecordFuzzer ( 3 )
284
+ . exampleGenerator ( b ) ;
285
+ let ml = 0 ;
286
+ for ( let i = 0 ; i < 100 ; i ++ ) {
287
+ ml = Math . max (
288
+ Object . getOwnPropertyNames ( r . encode ( [
289
+ i ,
290
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
291
+ ] ) as object ) . length ,
292
+ ml
293
+ ) ;
294
+ }
295
+ assert . ok ( ml > 3 ) ;
296
+ } ) ;
297
+
298
+ it ( `overrides apply to the underlying registry` , ( ) => {
299
+ const b = t . record ( t . string , t . number ) ;
300
+ const r0 = lib . createCoreRegistry ( ) ;
301
+ lib . fluent ( r0 ) . withRecordFuzzer ( 3 ) ;
302
+ const r = r0 . exampleGenerator ( b ) ;
303
+ for ( let i = 0 ; i < 100 ; i ++ ) {
304
+ assert . ok (
305
+ Object . getOwnPropertyNames ( r . encode ( [
306
+ i ,
307
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
308
+ ] ) as object ) . length <= 3
309
+ ) ;
310
+ }
311
+ } ) ;
312
+ } ) ;
313
+ } ) ;
314
+
315
+ describe ( '#withUnknownRecordFuzzer' , ( ) => {
316
+ describe ( 'on the core registry' , ( ) => {
317
+ it ( `overrides the unknown record fuzzer max count` , ( ) => {
318
+ const b = t . UnknownRecord ;
319
+ const r0 = lib . createCoreRegistry ( ) ;
320
+ const r = lib
321
+ . fluent ( r0 )
322
+ . withUnknownRecordFuzzer ( 3 )
323
+ . exampleGenerator ( b ) ;
324
+ for ( let i = 0 ; i < 100 ; i ++ ) {
325
+ assert . ok (
326
+ Object . getOwnPropertyNames ( r . encode ( [
327
+ i ,
328
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
329
+ ] ) as object ) . length <= 3
330
+ ) ;
331
+ }
332
+ } ) ;
333
+
334
+ it ( `does not affect records` , ( ) => {
335
+ const b = t . record ( t . string , t . unknown ) ;
336
+ const r0 = lib . createCoreRegistry ( ) ;
337
+ const r = lib
338
+ . fluent ( r0 )
339
+ . withUnknownRecordFuzzer ( 3 )
340
+ . exampleGenerator ( b ) ;
341
+ let ml = 0 ;
342
+ for ( let i = 0 ; i < 100 ; i ++ ) {
343
+ ml = Math . max (
344
+ Object . getOwnPropertyNames ( r . encode ( [
345
+ i ,
346
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
347
+ ] ) as object ) . length ,
348
+ ml
349
+ ) ;
350
+ }
351
+ assert . ok ( ml > 3 ) ;
352
+ } ) ;
353
+
354
+ it ( `overrides apply to the underlying registry` , ( ) => {
355
+ const b = t . UnknownRecord ;
356
+ const r0 = lib . createCoreRegistry ( ) ;
357
+ lib . fluent ( r0 ) . withUnknownRecordFuzzer ( 3 ) ;
358
+ const r = r0 . exampleGenerator ( b ) ;
359
+ for ( let i = 0 ; i < 100 ; i ++ ) {
360
+ assert . ok (
361
+ Object . getOwnPropertyNames ( r . encode ( [
362
+ i ,
363
+ fuzzContext ( { maxRecursionHint : 10 } ) ,
364
+ ] ) as object ) . length <= 3
365
+ ) ;
366
+ }
367
+ } ) ;
368
+ } ) ;
369
+ } ) ;
370
+
259
371
describe ( '#withAnyArrayFuzzer' , ( ) => {
260
372
describe ( 'on the core registry' , ( ) => {
261
373
it ( `overrides the any array fuzzer max length` , ( ) => {
0 commit comments