@@ -39,6 +39,28 @@ describe('string', () => {
3939 } ) ;
4040 } ) ;
4141
42+ t . describe ( 'binary' , ( t ) => {
43+ t . it ( 'noArgs' )
44+ . it ( 'with length' , { length : 6 } )
45+ . it ( 'with length range' , { length : { min : 10 , max : 20 } } )
46+ . it ( 'with custom prefix' , { prefix : 'bin_' } )
47+ . it ( 'with length and empty prefix' , {
48+ length : 7 ,
49+ prefix : '' ,
50+ } ) ;
51+ } ) ;
52+
53+ t . describe ( 'octal' , ( t ) => {
54+ t . it ( 'noArgs' )
55+ . it ( 'with length' , { length : 6 } )
56+ . it ( 'with length range' , { length : { min : 10 , max : 20 } } )
57+ . it ( 'with custom prefix' , { prefix : 'oct_' } )
58+ . it ( 'with length and empty prefix' , {
59+ length : 7 ,
60+ prefix : '' ,
61+ } ) ;
62+ } ) ;
63+
4264 t . describe ( 'hexadecimal' , ( t ) => {
4365 t . it ( 'noArgs' )
4466 . it ( 'with length' , { length : 6 } )
@@ -344,6 +366,84 @@ describe('string', () => {
344366 } ) ;
345367 } ) ;
346368
369+ describe ( `binary` , ( ) => {
370+ it ( 'generates a single binary character when no additional argument was provided' , ( ) => {
371+ const binary = faker . string . binary ( ) ;
372+ expect ( binary ) . toMatch ( / ^ 0 b [ 0 1 ] $ / i) ;
373+ expect ( binary ) . toHaveLength ( 3 ) ;
374+ } ) ;
375+
376+ it ( 'generates a random binary string with fixed length and no prefix' , ( ) => {
377+ const binary = faker . string . binary ( {
378+ length : 5 ,
379+ prefix : '' ,
380+ } ) ;
381+ expect ( binary ) . toMatch ( / ^ [ 0 1 ] * $ / i) ;
382+ expect ( binary ) . toHaveLength ( 5 ) ;
383+ } ) ;
384+
385+ it . each ( [ 0 , - 1 , - 100 ] ) (
386+ 'should return the prefix when length is <= 0' ,
387+ ( length ) => {
388+ const binary = faker . string . binary ( { length } ) ;
389+
390+ expect ( binary ) . toBe ( '0b' ) ;
391+ }
392+ ) ;
393+
394+ it ( 'should return a binary string with a random amount of characters and no prefix' , ( ) => {
395+ const binary = faker . string . binary ( {
396+ length : { min : 10 , max : 20 } ,
397+ prefix : '' ,
398+ } ) ;
399+
400+ expect ( binary ) . toBeDefined ( ) ;
401+ expect ( binary ) . toBeTypeOf ( 'string' ) ;
402+
403+ expect ( binary . length ) . toBeGreaterThanOrEqual ( 10 ) ;
404+ expect ( binary . length ) . toBeLessThanOrEqual ( 20 ) ;
405+ } ) ;
406+ } ) ;
407+
408+ describe ( `octal` , ( ) => {
409+ it ( 'generates single octal character when no additional argument was provided' , ( ) => {
410+ const octal = faker . string . octal ( ) ;
411+ expect ( octal ) . toMatch ( / ^ 0 o [ 0 - 7 ] $ / i) ;
412+ expect ( octal ) . toHaveLength ( 3 ) ;
413+ } ) ;
414+
415+ it ( 'generates a random octal string with fixed length and no prefix' , ( ) => {
416+ const octal = faker . string . octal ( {
417+ length : 5 ,
418+ prefix : '' ,
419+ } ) ;
420+ expect ( octal ) . toMatch ( / ^ [ 0 - 7 ] * $ / i) ;
421+ expect ( octal ) . toHaveLength ( 5 ) ;
422+ } ) ;
423+
424+ it . each ( [ 0 , - 1 , - 100 ] ) (
425+ 'should return the prefix when length is <= 0' ,
426+ ( length ) => {
427+ const octal = faker . string . octal ( { length } ) ;
428+
429+ expect ( octal ) . toBe ( '0o' ) ;
430+ }
431+ ) ;
432+
433+ it ( 'should return an octal string with a random amount of characters and no prefix' , ( ) => {
434+ const octal = faker . string . octal ( {
435+ length : { min : 10 , max : 20 } ,
436+ prefix : '' ,
437+ } ) ;
438+
439+ expect ( octal ) . toBeDefined ( ) ;
440+ expect ( octal ) . toBeTypeOf ( 'string' ) ;
441+
442+ expect ( octal . length ) . toBeGreaterThanOrEqual ( 10 ) ;
443+ expect ( octal . length ) . toBeLessThanOrEqual ( 20 ) ;
444+ } ) ;
445+ } ) ;
446+
347447 describe ( `hexadecimal` , ( ) => {
348448 it ( 'generates single hex character when no additional argument was provided' , ( ) => {
349449 const hex = faker . string . hexadecimal ( ) ;
0 commit comments