make argv handling reusable

This commit is contained in:
Martin Aeschlimann
2019-01-21 12:59:20 +01:00
parent 5d00c4b2ca
commit efc4d93818
5 changed files with 269 additions and 227 deletions

View File

@@ -3,37 +3,55 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { formatOptions } from 'vs/platform/environment/node/argv';
import { formatOptions, Option } from 'vs/platform/environment/node/argv';
suite('formatOptions', () => {
function o(id: string, description: string): Option {
return {
id, description, type: 'string'
};
}
test('Text should display small columns correctly', () => {
assert.equal(formatOptions({ 'foo': 'bar' }, 80), ' foo bar');
assert.equal(
formatOptions({
'f': 'bar',
'fo': 'ba',
'foo': 'b'
}, 80),
' f bar\n' +
' fo ba\n' +
' foo b');
assert.deepEqual(
formatOptions([
o('foo', 'bar')
], 80),
[' --foo bar']
);
assert.deepEqual(
formatOptions([
o('f', 'bar'),
o('fo', 'ba'),
o('foo', 'b')
], 80),
[
' --f bar',
' --fo ba',
' --foo b'
]);
});
test('Text should wrap', () => {
assert.equal(
formatOptions({
'foo': (<any>'bar ').repeat(9)
}, 40),
' foo bar bar bar bar bar bar bar bar\n' +
' bar');
assert.deepEqual(
formatOptions([
o('foo', (<any>'bar ').repeat(9))
], 40),
[
' --foo bar bar bar bar bar bar bar bar',
' bar'
]);
});
test('Text should revert to the condensed view when the terminal is too narrow', () => {
assert.equal(
formatOptions({
'foo': (<any>'bar ').repeat(9)
}, 30),
' foo\n' +
' bar bar bar bar bar bar bar bar bar ');
assert.deepEqual(
formatOptions([
o('foo', (<any>'bar ').repeat(9))
], 30),
[
' --foo',
' bar bar bar bar bar bar bar bar bar '
]);
});
});