|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import * as TypeMoq from 'typemoq'; |
| 5 | +import { OutputChannel, TextDocument, Uri } from 'vscode'; |
| 6 | +import { IDocumentManager, IWorkspaceService } from '../../client/common/application/types'; |
| 7 | +import { PythonLanguage, STANDARD_OUTPUT_CHANNEL } from '../../client/common/constants'; |
| 8 | +import '../../client/common/extensions'; |
| 9 | +import { IConfigurationService, ILintingSettings, IOutputChannel, IPythonSettings } from '../../client/common/types'; |
| 10 | +import { IServiceContainer } from '../../client/ioc/types'; |
| 11 | +import { LintingEngine } from '../../client/linters/lintingEngine'; |
| 12 | +import { ILinterManager, ILintingEngine } from '../../client/linters/types'; |
| 13 | +import { initialize } from '../initialize'; |
| 14 | + |
| 15 | +// tslint:disable-next-line:max-func-body-length |
| 16 | +suite('Linting - LintingEngine', () => { |
| 17 | + let lintingEnging: ILintingEngine; |
| 18 | + let document: TextDocument; |
| 19 | + let lintManager: TypeMoq.IMock<ILinterManager>; |
| 20 | + suiteSetup(initialize); |
| 21 | + setup(async () => { |
| 22 | + const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); |
| 23 | + |
| 24 | + const docManager = TypeMoq.Mock.ofType<IDocumentManager>(); |
| 25 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IDocumentManager), TypeMoq.It.isAny())).returns(() => docManager.object); |
| 26 | + |
| 27 | + const workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>(); |
| 28 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IWorkspaceService), TypeMoq.It.isAny())).returns(() => workspaceService.object); |
| 29 | + |
| 30 | + const lintSettings = TypeMoq.Mock.ofType<ILintingSettings>(); |
| 31 | + lintSettings.setup(l => l.ignorePatterns).returns(() => []); |
| 32 | + const settings = TypeMoq.Mock.ofType<IPythonSettings>(); |
| 33 | + settings.setup(x => x.linting).returns(() => lintSettings.object); |
| 34 | + const configService = TypeMoq.Mock.ofType<IConfigurationService>(); |
| 35 | + configService.setup(x => x.getSettings(TypeMoq.It.isAny())).returns(() => settings.object); |
| 36 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IConfigurationService), TypeMoq.It.isAny())).returns(() => configService.object); |
| 37 | + |
| 38 | + const outputChannel = TypeMoq.Mock.ofType<OutputChannel>(); |
| 39 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(IOutputChannel), TypeMoq.It.isValue(STANDARD_OUTPUT_CHANNEL))).returns(() => outputChannel.object); |
| 40 | + |
| 41 | + lintManager = TypeMoq.Mock.ofType<ILinterManager>(); |
| 42 | + serviceContainer.setup(c => c.get(TypeMoq.It.isValue(ILinterManager), TypeMoq.It.isAny())).returns(() => lintManager.object); |
| 43 | + |
| 44 | + const mockDocument = TypeMoq.Mock.ofType<TextDocument>(); |
| 45 | + mockDocument.setup(d => d.uri).returns(() => Uri.file('a.py')); |
| 46 | + mockDocument.setup(d => d.languageId).returns(() => PythonLanguage.language); |
| 47 | + document = mockDocument.object; |
| 48 | + |
| 49 | + lintingEnging = new LintingEngine(serviceContainer.object); |
| 50 | + }); |
| 51 | + |
| 52 | + test('Ensure document.uri is passed into isLintingEnabled', () => { |
| 53 | + try { |
| 54 | + lintingEnging.lintDocument(document, 'auto').ignoreErrors(); |
| 55 | + } catch { |
| 56 | + lintManager.verify(l => l.isLintingEnabled(TypeMoq.It.isValue(document.uri)), TypeMoq.Times.once()); |
| 57 | + } |
| 58 | + }); |
| 59 | + test('Ensure document.uri is passed into createLinter', () => { |
| 60 | + try { |
| 61 | + lintingEnging.lintDocument(document, 'auto').ignoreErrors(); |
| 62 | + } catch { |
| 63 | + lintManager.verify(l => l.createLinter(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isValue(document.uri)), TypeMoq.Times.atLeastOnce()); |
| 64 | + } |
| 65 | + }); |
| 66 | +}); |
0 commit comments