-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
string.test.ts
51 lines (44 loc) · 1023 Bytes
/
string.test.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
import { expect, it } from 'vitest'
import { ensurePrefix, ensureSuffix, slash, template } from './string'
it('template', () => {
expect(
template(
'Hello {0}! My name is {1}.',
'Inès',
'Anthony',
),
).toEqual('Hello Inès! My name is Anthony.')
expect(
template(
'{0} + {1} = {2}{3}',
1,
'1',
{ v: 2 },
[2, 3],
),
).toEqual('1 + 1 = [object Object]2,3')
expect(
template(
'{10}',
),
).toEqual('undefined')
expect(
template(
'Hi',
'',
),
).toEqual('Hi')
})
it('slash', () => {
expect(slash('\\123')).toEqual('/123')
expect(slash('\\\\')).toEqual('//')
expect(slash('\\\h\\\i')).toEqual('/h/i')
})
it('ensurePrefix', () => {
expect(ensurePrefix('abc', 'abcdef')).toEqual('abcdef')
expect(ensurePrefix('hi ', 'jack')).toEqual('hi jack')
})
it('ensureSuffix', () => {
expect(ensureSuffix('world', 'hello ')).toEqual('hello world')
expect(ensureSuffix('123', 'abc123')).toEqual('abc123')
})