-
-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathutils.test.ts
56 lines (51 loc) · 1.25 KB
/
utils.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
52
53
54
55
56
import { format, generateCodeFrame, makeSymbol, join } from '../src/index'
test('format', () => {
expect(format(`foo: {0}`, 'x')).toEqual('foo: x')
expect(format(`foo: {0}, {1}`, 'x', 'y')).toEqual('foo: x, y')
expect(format(`foo: {x}, {y}`, { x: 1, y: 2 })).toEqual('foo: 1, 2')
})
test('generateCodeFrame', () => {
const source = `hi, { 'kazupon' }`.trim()
const keyStart = source.indexOf(`{ 'kazupon' }`)
const keyEnd = keyStart + `{ 'kazupon' }`.length
expect(generateCodeFrame(source, keyStart, keyEnd)).toMatchSnapshot()
})
test('makeSymbol', () => {
expect(makeSymbol('foo')).not.toEqual(makeSymbol('foo'))
expect(makeSymbol('bar', true)).toEqual(makeSymbol('bar', true))
})
test('join', () => {
expect(join([])).toEqual([].join(''))
expect(join(['a'], ',')).toEqual(['a'].join(','))
expect(join(['a', 'b', 'c'])).toEqual(['a', 'b', 'c'].join(''))
expect(join(['a', 'b', 'c'], ' ')).toEqual(['a', 'b', 'c'].join(' '))
const longSize = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
]
expect(join(longSize, ' ')).toEqual(longSize.join(' '))
})