Path: blob/main/src/vs/workbench/test/common/resources.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { DisposableStore } from '../../../base/common/lifecycle.js';7import { URI } from '../../../base/common/uri.js';8import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../base/test/common/utils.js';9import { TestConfigurationService } from '../../../platform/configuration/test/common/testConfigurationService.js';10import { IWorkspaceContextService } from '../../../platform/workspace/common/workspace.js';11import { ResourceGlobMatcher } from '../../common/resources.js';12import { TestContextService } from './workbenchTestServices.js';1314suite('ResourceGlobMatcher', () => {1516const SETTING = 'test.matcher';1718let contextService: IWorkspaceContextService;19let configurationService: TestConfigurationService;2021const disposables = new DisposableStore();2223setup(() => {24contextService = new TestContextService();25configurationService = new TestConfigurationService({26[SETTING]: {27'**/*.md': true,28'**/*.txt': false29}30});31});3233teardown(() => {34disposables.clear();35});3637test('Basics', async () => {38const matcher = disposables.add(new ResourceGlobMatcher(() => configurationService.getValue(SETTING), e => e.affectsConfiguration(SETTING), contextService, configurationService));3940// Matching41assert.equal(matcher.matches(URI.file('/foo/bar')), false);42assert.equal(matcher.matches(URI.file('/foo/bar.md')), true);43assert.equal(matcher.matches(URI.file('/foo/bar.txt')), false);4445// Events46let eventCounter = 0;47disposables.add(matcher.onExpressionChange(() => eventCounter++));4849await configurationService.setUserConfiguration(SETTING, { '**/*.foo': true });50configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);51assert.equal(eventCounter, 1);5253assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);54assert.equal(matcher.matches(URI.file('/foo/bar.foo')), true);5556await configurationService.setUserConfiguration(SETTING, undefined);57configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);58assert.equal(eventCounter, 2);5960assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);61assert.equal(matcher.matches(URI.file('/foo/bar.foo')), false);6263await configurationService.setUserConfiguration(SETTING, {64'**/*.md': true,65'**/*.txt': false,66'C:/bar/**': true,67'/bar/**': true68});69configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);7071assert.equal(matcher.matches(URI.file('/bar/foo.1')), true);72assert.equal(matcher.matches(URI.file('C:/bar/foo.1')), true);73});7475ensureNoDisposablesAreLeakedInTestSuite();76});777879