aboutsummaryrefslogtreecommitdiff
path: root/tests/replace.spec.ts
blob: dd82eaaa4491b007fcbbfcc17c25cb3b611e795b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { jlog } from '../src/utils'
import { replaceAll } from '../src'

describe('Basic tests', () => {
  it('should', () => {
    expect(
      replaceAll(/"start", \s, \n/, _ => ['replaced'], [
        1,
        'start',
        'x',
        2,
        'start',
        3,
        'start',
        'y',
        4,
      ]),
    ).toEqual([1, 'replaced', 'start', 3, 'replaced'])
  })

  it('should replace matching items', () => {
    expect(replaceAll(/\F/, (_x, _i) => [69], [1, 5, 0, 0, 2, 9, 0])).toEqual([
      1, 5, 69, 69, 2, 9, 69,
    ])

    expect(
      replaceAll(/\s+/, (_x, m) => [(m.value as any).join(',')], [
        1,
        'wow',
        'test',
        [],
        '0',
        2,
        '',
        'nice',
      ]),
    ).toEqual([1, 'wow,test', [], '0', 2, ',nice'])
  })
})