/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { formatOptions, Option } from 'vs/platform/environment/node/argv'; import { addArg } from 'vs/platform/environment/node/argvHelper'; suite('formatOptions', () => { function o(description: string): Option { return { description, type: 'string' }; } test('Text should display small columns correctly', () => { assert.deepStrictEqual( formatOptions({ 'add': o('bar') }, 80), [' --add bar'] ); assert.deepStrictEqual( formatOptions({ 'add': o('bar'), 'wait': o('ba'), 'trace': o('b') }, 80), [ ' --add bar', ' --wait ba', ' --trace b' ]); }); test('Text should wrap', () => { assert.deepStrictEqual( formatOptions({ 'add': o(('bar ').repeat(9)) }, 40), [ ' --add bar bar bar bar bar bar bar bar', ' bar' ]); }); test('Text should revert to the condensed view when the terminal is too narrow', () => { assert.deepStrictEqual( formatOptions({ 'add': o(('bar ').repeat(9)) }, 30), [ ' --add', ' bar bar bar bar bar bar bar bar bar ' ]); }); test('addArg', () => { assert.deepStrictEqual(addArg([], 'foo'), ['foo']); assert.deepStrictEqual(addArg([], 'foo', 'bar'), ['foo', 'bar']); assert.deepStrictEqual(addArg(['foo'], 'bar'), ['foo', 'bar']); assert.deepStrictEqual(addArg(['--wait'], 'bar'), ['--wait', 'bar']); assert.deepStrictEqual(addArg(['--wait', '--', '--foo'], 'bar'), ['--wait', 'bar', '--', '--foo']); assert.deepStrictEqual(addArg(['--', '--foo'], 'bar'), ['bar', '--', '--foo']); }); });