|  | 
|  | 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. | 
|  | 2 | +// Licensed under the MIT License. | 
|  | 3 | + | 
|  | 4 | +'use strict'; | 
|  | 5 | + | 
|  | 6 | +import { expect } from 'chai'; | 
|  | 7 | +import { anyString, instance, mock, when } from 'ts-mockito'; | 
|  | 8 | +import { Logger } from '../../client/common/logger'; | 
|  | 9 | +import { ILogger } from '../../client/common/types'; | 
|  | 10 | +import { ServiceContainer } from '../../client/ioc/container'; | 
|  | 11 | +import { IServiceContainer } from '../../client/ioc/types'; | 
|  | 12 | +import { ArgumentsHelper } from '../../client/testing/common/argumentsHelper'; | 
|  | 13 | + | 
|  | 14 | +suite('ArgumentsHelper tests', () => { | 
|  | 15 | + let argumentsHelper: ArgumentsHelper; | 
|  | 16 | + | 
|  | 17 | + setup(() => { | 
|  | 18 | + const logger: ILogger = mock(Logger); | 
|  | 19 | + when(logger.logWarning(anyString())).thenReturn(); | 
|  | 20 | + const serviceContainer: IServiceContainer = mock(ServiceContainer); | 
|  | 21 | + when(serviceContainer.get<ILogger>(ILogger)).thenReturn(instance(logger)); | 
|  | 22 | + | 
|  | 23 | + argumentsHelper = new ArgumentsHelper(instance(serviceContainer)); | 
|  | 24 | + }); | 
|  | 25 | + | 
|  | 26 | + test('getPositionalArguments with both options parameters should return correct positional arguments', () => { | 
|  | 27 | + const args = ['arg1', '--foo', 'arg2', '--bar', 'arg3', 'arg4']; | 
|  | 28 | + const optionsWithArguments = ['--bar']; | 
|  | 29 | + const optionsWithoutArguments = ['--foo']; | 
|  | 30 | + const result = argumentsHelper.getPositionalArguments(args, optionsWithArguments, optionsWithoutArguments); | 
|  | 31 | + | 
|  | 32 | + expect(result).to.have.length(3); | 
|  | 33 | + expect(result).to.deep.equal(['arg1', 'arg2', 'arg4']); | 
|  | 34 | + }); | 
|  | 35 | + | 
|  | 36 | + test('getPositionalArguments with optionsWithArguments with inline `option=value` syntax should return correct positional arguments', () => { | 
|  | 37 | + const args = ['arg1', '--foo', 'arg2', '--bar=arg3', 'arg4']; | 
|  | 38 | + const optionsWithArguments = ['--bar']; | 
|  | 39 | + const optionsWithoutArguments = ['--foo']; | 
|  | 40 | + const result = argumentsHelper.getPositionalArguments(args, optionsWithArguments, optionsWithoutArguments); | 
|  | 41 | + | 
|  | 42 | + expect(result).to.have.length(3); | 
|  | 43 | + expect(result).to.deep.equal(['arg1', 'arg2', 'arg4']); | 
|  | 44 | + }); | 
|  | 45 | + | 
|  | 46 | + test('getPositionalArguments with unknown arguments with inline `option=value` syntax should return correct positional arguments', () => { | 
|  | 47 | + const args = ['arg1', '--foo', 'arg2', 'bar=arg3', 'arg4']; | 
|  | 48 | + const optionsWithArguments: string[] = []; | 
|  | 49 | + const optionsWithoutArguments = ['--foo']; | 
|  | 50 | + const result = argumentsHelper.getPositionalArguments(args, optionsWithArguments, optionsWithoutArguments); | 
|  | 51 | + | 
|  | 52 | + expect(result).to.have.length(3); | 
|  | 53 | + expect(result).to.deep.equal(['arg1', 'arg2', 'arg4']); | 
|  | 54 | + }); | 
|  | 55 | + | 
|  | 56 | + test('getPositionalArguments with no options parameter should be the same as passing empty arrays', () => { | 
|  | 57 | + const args = ['arg1', '--foo', 'arg2', '--bar', 'arg3', 'arg4']; | 
|  | 58 | + const optionsWithArguments: string[] = []; | 
|  | 59 | + const optionsWithoutArguments: string[] = []; | 
|  | 60 | + const result = argumentsHelper.getPositionalArguments(args, optionsWithArguments, optionsWithoutArguments); | 
|  | 61 | + | 
|  | 62 | + expect(result).to.deep.equal(argumentsHelper.getPositionalArguments(args)); | 
|  | 63 | + expect(result).to.have.length(4); | 
|  | 64 | + expect(result).to.deep.equal(['arg1', 'arg2', 'arg3', 'arg4']); | 
|  | 65 | + }); | 
|  | 66 | +}); | 
0 commit comments