/
index.ts
113 lines (111 loc) · 3.31 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
102
103
104
105
106
107
108
109
110
111
112
113
import { createMatcher, createMatcherWithIndex } from '@pnpm/matcher'
test('matcher()', () => {
{
const match = createMatcher('*')
expect(match('@eslint/plugin-foo')).toBe(true)
expect(match('express')).toBe(true)
}
{
const match = createMatcher(['eslint-*'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = createMatcher(['*plugin*'])
expect(match('@eslint/plugin-foo')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = createMatcher(['a*c'])
expect(match('abc')).toBe(true)
}
{
const match = createMatcher(['*-positive'])
expect(match('is-positive')).toBe(true)
}
{
const match = createMatcher(['foo', 'bar'])
expect(match('foo')).toBe(true)
expect(match('bar')).toBe(true)
expect(match('express')).toBe(false)
}
{
const match = createMatcher(['eslint-*', '!eslint-plugin-bar'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('eslint-plugin-bar')).toBe(false)
}
{
const match = createMatcher(['!eslint-plugin-bar', 'eslint-*'])
expect(match('eslint-plugin-foo')).toBe(true)
expect(match('eslint-plugin-bar')).toBe(true)
}
{
const match = createMatcher(['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('createMatcherWithIndex()', () => {
{
const match = createMatcherWithIndex(['*'])
expect(match('@eslint/plugin-foo')).toBe(0)
expect(match('express')).toBe(0)
}
{
const match = createMatcherWithIndex(['eslint-*'])
expect(match('eslint-plugin-foo')).toBe(0)
expect(match('express')).toBe(-1)
}
{
const match = createMatcherWithIndex(['*plugin*'])
expect(match('@eslint/plugin-foo')).toBe(0)
expect(match('express')).toBe(-1)
}
{
const match = createMatcherWithIndex(['a*c'])
expect(match('abc')).toBe(0)
}
{
const match = createMatcherWithIndex(['*-positive'])
expect(match('is-positive')).toBe(0)
}
{
const match = createMatcherWithIndex(['foo', 'bar'])
expect(match('foo')).toBe(0)
expect(match('bar')).toBe(1)
expect(match('express')).toBe(-1)
}
{
const match = createMatcherWithIndex(['eslint-*', '!eslint-plugin-bar'])
expect(match('eslint-plugin-foo')).toBe(0)
expect(match('eslint-plugin-bar')).toBe(-1)
}
{
const match = createMatcherWithIndex(['!eslint-plugin-bar', 'eslint-*'])
expect(match('eslint-plugin-foo')).toBe(1)
expect(match('eslint-plugin-bar')).toBe(1)
}
{
const match = createMatcherWithIndex(['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 = createMatcherWithIndex(['!@pnpm.e2e/peer-*'])
expect(match('@pnpm.e2e/foo')).toBe(0)
}
{
const match = createMatcherWithIndex(['!foo', '!bar'])
expect(match('foo')).toBe(-1)
expect(match('bar')).toBe(-1)
expect(match('baz')).toBe(0)
}
{
const match = createMatcherWithIndex(['!foo', '!bar', 'qar'])
expect(match('foo')).toBe(-1)
expect(match('bar')).toBe(-1)
expect(match('baz')).toBe(-1)
}
})