/
index.ts
101 lines (99 loc) · 2.85 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import matcher, { matcherWithIndex } from '@pnpm/matcher'
test('matcher()', () => {
{
const match = matcher('*')
expect(match('@eslint/plugin-foo')).toBe(true)
expect(match('express')).toBe(true)
}
{
const match = matcher(['eslint-*'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = matcher(['*plugin*'])
expect(match('@eslint/plugin-foo')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = matcher(['a*c'])
expect(match('abc')).toBe(true)
}
{
const match = matcher(['*-positive'])
expect(match('is-positive')).toBe(true)
}
{
const match = matcher(['foo', 'bar'])
expect(match('foo')).toBe(true)
expect(match('bar')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = matcher(['eslint-*', '!eslint-plugin-bar'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('eslint-plugin-bar')).toBe(false)
}
{
const match = matcher(['!eslint-plugin-bar', 'eslint-*'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('eslint-plugin-bar')).toBe(true)
}
{
const match = matcher(['eslint-*', '!eslint-plugin-*', 'eslint-plugin-bar'])
expect(match('eslint-config-foo')).toBe(true)
expect(match('eslint-plugin-foo')).toBe(false)
expect(match('eslint-plugin-bar')).toBe(true)
}
})
test('matcherWithIndex()', () => {
{
const match = matcherWithIndex(['*'])
expect(match('@eslint/plugin-foo')).toBe(0)
expect(match('express')).toBe(0)
}
{
const match = matcherWithIndex(['eslint-*'])
expect(match('eslint-plugin-foo')).toBe(0)
expect(match('express')).toBe(-1)
}
{
const match = matcherWithIndex(['*plugin*'])
expect(match('@eslint/plugin-foo')).toBe(0)
expect(match('express')).toBe(-1)
}
{
const match = matcherWithIndex(['a*c'])
expect(match('abc')).toBe(0)
}
{
const match = matcherWithIndex(['*-positive'])
expect(match('is-positive')).toBe(0)
}
{
const match = matcherWithIndex(['foo', 'bar'])
expect(match('foo')).toBe(0)
expect(match('bar')).toBe(1)
expect(match('express')).toBe(-1)
}
{
const match = matcherWithIndex(['eslint-*', '!eslint-plugin-bar'])
expect(match('eslint-plugin-foo')).toBe(0)
expect(match('eslint-plugin-bar')).toBe(-1)
}
{
const match = matcherWithIndex(['!eslint-plugin-bar', 'eslint-*'])
expect(match('eslint-plugin-foo')).toBe(0)
expect(match('eslint-plugin-bar')).toBe(1)
}
{
const match = matcherWithIndex(['eslint-*', '!eslint-plugin-*', 'eslint-plugin-bar'])
expect(match('eslint-config-foo')).toBe(0)
expect(match('eslint-plugin-foo')).toBe(-1)
expect(match('eslint-plugin-bar')).toBe(2)
}
{
const match = matcherWithIndex(['!@pnpm.e2e/peer-*'])
expect(match('@pnpm.e2e/foo')).toBe(0)
}
})