forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargsHelper.unit.test.ts
More file actions
116 lines (112 loc) · 6.11 KB
/
argsHelper.unit.test.ts
File metadata and controls
116 lines (112 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:max-func-body-length no-any no-conditional-assignment no-increment-decrement no-invalid-this no-require-imports no-var-requires
import { expect, use } from 'chai';
import { ArgumentsHelper } from '../../../client/testing/common/argumentsHelper';
import { IArgumentsHelper } from '../../../client/testing/types';
const assertArrays = require('chai-arrays');
use(assertArrays);
suite('Unit Tests - Arguments Helper', () => {
let argsHelper: IArgumentsHelper;
setup(() => {
argsHelper = new ArgumentsHelper();
});
test('Get Option Value', () => {
const args = ['-abc', '1234', 'zys', '--root', 'value'];
const value = argsHelper.getOptionValues(args, '--root');
expect(value).to.not.be.array();
expect(value).to.be.deep.equal('value');
});
test('Get Option Value when using =', () => {
const args = ['-abc', '1234', 'zys', '--root=value'];
const value = argsHelper.getOptionValues(args, '--root');
expect(value).to.not.be.array();
expect(value).to.be.deep.equal('value');
});
test('Get Option Values', () => {
const args = ['-abc', '1234', 'zys', '--root', 'value1', '--root', 'value2'];
const values = argsHelper.getOptionValues(args, '--root');
expect(values).to.be.array();
expect(values).to.be.lengthOf(2);
expect(values).to.be.deep.equal(['value1', 'value2']);
});
test('Get Option Values when using =', () => {
const args = ['-abc', '1234', 'zys', '--root=value1', '--root=value2'];
const values = argsHelper.getOptionValues(args, '--root');
expect(values).to.be.array();
expect(values).to.be.lengthOf(2);
expect(values).to.be.deep.equal(['value1', 'value2']);
});
test('Get Positional options', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--no-value-option', 'value2'];
const values = argsHelper.getPositionalArguments(args, ['--value-option', '-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(1);
expect(values).to.be.deep.equal(['value2']);
});
test('Get multiple Positional options', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--no-value-option', 'value2', 'value3'];
const values = argsHelper.getPositionalArguments(args, ['--value-option', '-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(2);
expect(values).to.be.deep.equal(['value2', 'value3']);
});
test('Get multiple Positional options and inline values', () => {
const args = ['-abc=1234', '--value-option=value1', '--no-value-option', 'value2', 'value3'];
const values = argsHelper.getPositionalArguments(args, ['--value-option', '-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(2);
expect(values).to.be.deep.equal(['value2', 'value3']);
});
test('Get Positional options with trailing value option', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3'];
const values = argsHelper.getPositionalArguments(args, ['--value-option', '-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(1);
expect(values).to.be.deep.equal(['value3']);
});
test('Get multiple Positional options with trailing value option', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3', '4'];
const values = argsHelper.getPositionalArguments(args, ['--value-option', '-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(2);
expect(values).to.be.deep.equal(['value3', '4']);
});
test('Get Positional options with unknown args', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3', '4'];
const values = argsHelper.getPositionalArguments(args, ['-abc'], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(4);
expect(values).to.be.deep.equal(['value1', 'value2', 'value3', '4']);
});
test('Get Positional options with no options parameters', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3', '4'];
const values = argsHelper.getPositionalArguments(args);
expect(values).to.be.array();
expect(values).to.be.lengthOf(5);
expect(values).to.be.deep.equal(['1234', 'value1', 'value2', 'value3', '4']);
expect(values).to.be.deep.equal(argsHelper.getPositionalArguments(args, [], []));
});
test('Filter to remove those with values', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3', '4'];
const values = argsHelper.filterArguments(args, ['--value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(4);
expect(values).to.be.deep.equal(['-abc', '1234', 'value3', '4']);
});
test('Filter to remove those without values', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--no-value-option', 'value2', 'value3', '4'];
const values = argsHelper.filterArguments(args, [], ['--no-value-option']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(7);
expect(values).to.be.deep.equal(['-abc', '1234', '--value-option', 'value1', 'value2', 'value3', '4']);
});
test('Filter to remove those with and without values', () => {
const args = ['-abc', '1234', '--value-option', 'value1', '--value-option', 'value2', 'value3', '4'];
const values = argsHelper.filterArguments(args, ['--value-option'], ['-abc']);
expect(values).to.be.array();
expect(values).to.be.lengthOf(3);
expect(values).to.be.deep.equal(['1234', 'value3', '4']);
});
});