Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/test/common/resources.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { DisposableStore } from '../../../base/common/lifecycle.js';
8
import { URI } from '../../../base/common/uri.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';
10
import { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';
11
import { IWorkspaceContextService } from '../../../platform/workspace/common/workspace.js';
12
import { ResourceGlobMatcher } from '../../common/resources.js';
13
import { TestContextService } from './workbenchTestServices.js';
14
15
suite('ResourceGlobMatcher', () => {
16
17
const SETTING = 'test.matcher';
18
19
let contextService: IWorkspaceContextService;
20
let configurationService: TestConfigurationService;
21
22
const disposables = new DisposableStore();
23
24
setup(() => {
25
contextService = new TestContextService();
26
configurationService = new TestConfigurationService({
27
[SETTING]: {
28
'**/*.md': true,
29
'**/*.txt': false
30
}
31
});
32
});
33
34
teardown(() => {
35
disposables.clear();
36
});
37
38
test('Basics', async () => {
39
const matcher = disposables.add(new ResourceGlobMatcher(() => configurationService.getValue(SETTING), e => e.affectsConfiguration(SETTING), contextService, configurationService));
40
41
// Matching
42
assert.equal(matcher.matches(URI.file('/foo/bar')), false);
43
assert.equal(matcher.matches(URI.file('/foo/bar.md')), true);
44
assert.equal(matcher.matches(URI.file('/foo/bar.txt')), false);
45
46
// Events
47
let eventCounter = 0;
48
disposables.add(matcher.onExpressionChange(() => eventCounter++));
49
50
await configurationService.setUserConfiguration(SETTING, { '**/*.foo': true });
51
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
52
assert.equal(eventCounter, 1);
53
54
assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);
55
assert.equal(matcher.matches(URI.file('/foo/bar.foo')), true);
56
57
await configurationService.setUserConfiguration(SETTING, undefined);
58
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
59
assert.equal(eventCounter, 2);
60
61
assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);
62
assert.equal(matcher.matches(URI.file('/foo/bar.foo')), false);
63
64
await configurationService.setUserConfiguration(SETTING, {
65
'**/*.md': true,
66
'**/*.txt': false,
67
'C:/bar/**': true,
68
'/bar/**': true
69
});
70
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
71
72
assert.equal(matcher.matches(URI.file('/bar/foo.1')), true);
73
assert.equal(matcher.matches(URI.file('C:/bar/foo.1')), true);
74
});
75
76
ensureNoDisposablesAreLeakedInTestSuite();
77
});
78
79