Skip to content

Commit a740f95

Browse files
cpinamtzeleanorjboyd
authored andcommitted
Add some more coverage to utils functions (microsoft#21026)
1 parent 0a6da5a commit a740f95

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

src/test/common/terminals/shellDetector.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ suite('Shell Detector', () => {
3434

3535
getNamesAndValues<OSType>(OSType).forEach((os) => {
3636
const testSuffix = `(OS ${os.name})`;
37-
test('Test identification of Terminal Shells in order of priority', async () => {
37+
test(`Test identification of Terminal Shells in order of priority ${testSuffix}`, async () => {
3838
const callOrder: string[] = [];
3939
const nameDetectorIdentify = sandbox.stub(TerminalNameShellDetector.prototype, 'identify');
4040
nameDetectorIdentify.callsFake(() => {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 { OSType } from '../../common';
8+
import { getSearchPathEnvVarNames } from '../../../client/common/utils/exec';
9+
10+
suite('Utils for exec - getSearchPathEnvVarNames function', () => {
11+
const testsData = [
12+
{ os: 'Unknown', expected: ['PATH'] },
13+
{ os: 'Windows', expected: ['Path', 'PATH'] },
14+
{ os: 'OSX', expected: ['PATH'] },
15+
{ os: 'Linux', expected: ['PATH'] },
16+
];
17+
18+
testsData.forEach((testData) => {
19+
test(`getSearchPathEnvVarNames when os is ${testData.os}`, () => {
20+
const pathVariables = getSearchPathEnvVarNames(testData.os as OSType);
21+
22+
expect(pathVariables).to.deep.equal(testData.expected);
23+
});
24+
});
25+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 { convertFileType } from '../../../client/common/utils/filesystem';
8+
9+
class KnowsFileTypeDummyImpl {
10+
private _isFile: boolean;
11+
12+
private _isDirectory: boolean;
13+
14+
private _isSymbolicLink: boolean;
15+
16+
constructor(isFile = false, isDirectory = false, isSymbolicLink = false) {
17+
this._isFile = isFile;
18+
this._isDirectory = isDirectory;
19+
this._isSymbolicLink = isSymbolicLink;
20+
}
21+
22+
public isFile() {
23+
return this._isFile;
24+
}
25+
26+
public isDirectory() {
27+
return this._isDirectory;
28+
}
29+
30+
public isSymbolicLink() {
31+
return this._isSymbolicLink;
32+
}
33+
}
34+
35+
suite('Utils for filesystem - convertFileType function', () => {
36+
const testsData = [
37+
{ info: new KnowsFileTypeDummyImpl(true, false, false), kind: 'File', expected: 1 },
38+
{ info: new KnowsFileTypeDummyImpl(false, true, false), kind: 'Directory', expected: 2 },
39+
{ info: new KnowsFileTypeDummyImpl(false, false, true), kind: 'Symbolic Link', expected: 64 },
40+
{ info: new KnowsFileTypeDummyImpl(false, false, false), kind: 'Unknown', expected: 0 },
41+
];
42+
43+
testsData.forEach((testData) => {
44+
test(`convertFileType when info is a ${testData.kind}`, () => {
45+
const fileType = convertFileType(testData.info);
46+
47+
expect(fileType).equals(testData.expected);
48+
});
49+
});
50+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 { OSType, getOSType } from '../../../client/common/utils/platform';
8+
9+
suite('Utils for platform - getOSType function', () => {
10+
const testsData = [
11+
{ platform: 'linux', expected: OSType.Linux },
12+
{ platform: 'darwin', expected: OSType.OSX },
13+
{ platform: 'anunknownplatform', expected: OSType.Unknown },
14+
{ platform: 'windows', expected: OSType.Windows },
15+
];
16+
17+
testsData.forEach((testData) => {
18+
test(`getOSType when platform is ${testData.platform}`, () => {
19+
const osType = getOSType(testData.platform);
20+
expect(osType).equal(testData.expected);
21+
});
22+
});
23+
});

src/test/common/utils/text.unit.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { expect } from 'chai';
77
import { Position, Range } from 'vscode';
8-
import { parsePosition, parseRange } from '../../../client/common/utils/text';
8+
import { getDedentedLines, getIndent, parsePosition, parseRange } from '../../../client/common/utils/text';
99

1010
suite('parseRange()', () => {
1111
test('valid strings', async () => {
@@ -98,3 +98,52 @@ suite('parsePosition()', () => {
9898
}
9999
});
100100
});
101+
102+
suite('getIndent()', () => {
103+
const testsData = [
104+
{ line: 'text', expected: '' },
105+
{ line: ' text', expected: ' ' },
106+
{ line: ' text', expected: ' ' },
107+
{ line: ' tabulatedtext', expected: '' },
108+
];
109+
110+
testsData.forEach((testData) => {
111+
test(`getIndent when line is ${testData.line}`, () => {
112+
const indent = getIndent(testData.line);
113+
114+
expect(indent).equal(testData.expected);
115+
});
116+
});
117+
});
118+
119+
suite('getDedentedLines()', () => {
120+
const testsData = [
121+
{ text: '', expected: [] },
122+
{ text: '\n', expected: Error, exceptionMessage: 'expected "first" line to not be blank' },
123+
{ text: 'line1\n', expected: Error, exceptionMessage: 'expected actual first line to be blank' },
124+
{
125+
text: '\n line2\n line3',
126+
expected: Error,
127+
exceptionMessage: 'line 1 has less indent than the "first" line',
128+
},
129+
{
130+
text: '\n line2\n line3',
131+
expected: ['line2', 'line3'],
132+
},
133+
{
134+
text: '\n line2\n line3',
135+
expected: ['line2', ' line3'],
136+
},
137+
];
138+
139+
testsData.forEach((testData) => {
140+
test(`getDedentedLines when line is ${testData.text}`, () => {
141+
if (Array.isArray(testData.expected)) {
142+
const dedentedLines = getDedentedLines(testData.text);
143+
expect(dedentedLines).to.deep.equal(testData.expected);
144+
} else {
145+
expect(() => getDedentedLines(testData.text)).to.throw(testData.expected, testData.exceptionMessage);
146+
}
147+
});
148+
});
149+
});

0 commit comments

Comments
 (0)