1
- import { randomInRange } from 'helpers'
1
+ import { randomInRange , substitute } from 'helpers'
2
2
3
3
describe ( 'randomInRange' , ( ) => {
4
4
test ( 'returns random number in range' , ( ) => {
@@ -13,3 +13,29 @@ describe('randomInRange', () => {
13
13
expect ( ( ) => { randomInRange ( 1 , 0 ) } ) . toThrowError ( 'Min cannot be larger than max' )
14
14
} )
15
15
} )
16
+
17
+ describe ( 'substitute' , ( ) => {
18
+ const mappingOptions = { mapping : { 'A' : 'M' } }
19
+ const mappingAndCaseInsensitiveOptions = { mapping : { 'A' : 'M' } , caseSensitive : false }
20
+ test ( 'default' , ( ) => {
21
+ expect ( substitute ( 'A' ) ) . toBe ( 'A' )
22
+ } )
23
+
24
+ test ( 'with custom mapping' , ( ) => {
25
+ expect ( substitute ( 'A' , mappingOptions ) ) . toBe ( 'M' )
26
+ expect ( substitute ( 'AMAMA' , mappingOptions ) ) . toBe ( 'MAMAM' )
27
+
28
+ expect ( substitute ( 'B' , mappingOptions ) ) . toBe ( 'B' )
29
+ } )
30
+
31
+ test ( 'case-insensitive' , ( ) => {
32
+ expect ( substitute ( 'Aa' , { caseSensitive : false } ) ) . toBe ( 'Aa' )
33
+ } )
34
+
35
+ test ( 'case-insensitive with custom mapping' , ( ) => {
36
+ expect ( substitute ( 'Aa' , mappingAndCaseInsensitiveOptions ) ) . toBe ( 'Mm' )
37
+ expect ( substitute ( 'AMamA' , mappingAndCaseInsensitiveOptions ) ) . toBe ( 'MAmaM' )
38
+
39
+ expect ( substitute ( 'B' , mappingAndCaseInsensitiveOptions ) ) . toBe ( 'B' )
40
+ } )
41
+ } )
0 commit comments