forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.unit.test.ts
More file actions
86 lines (85 loc) · 4.41 KB
/
extensions.unit.test.ts
File metadata and controls
86 lines (85 loc) · 4.41 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
import { expect } from 'chai';
import '../../client/common/extensions';
// Defines a Mocha test suite to group tests of similar kind together
suite('String Extensions', () => {
test('Should return empty string for empty arg', () => {
const argTotest = '';
expect(argTotest.toCommandArgument()).to.be.equal('');
});
test('Should quote an empty space', () => {
const argTotest = ' ';
expect(argTotest.toCommandArgument()).to.be.equal('" "');
});
test('Should not quote command arguments without spaces', () => {
const argTotest = 'one.two.three';
expect(argTotest.toCommandArgument()).to.be.equal(argTotest);
});
test('Should quote command arguments with spaces', () => {
const argTotest = 'one two three';
expect(argTotest.toCommandArgument()).to.be.equal(`"${argTotest}"`);
});
test('Should return empty string for empty path', () => {
const fileToTest = '';
expect(fileToTest.fileToCommandArgument()).to.be.equal('');
});
test('Should not quote file argument without spaces', () => {
const fileToTest = 'users/test/one';
expect(fileToTest.fileToCommandArgument()).to.be.equal(fileToTest);
});
test('Should quote file argument with spaces', () => {
const fileToTest = 'one two three';
expect(fileToTest.fileToCommandArgument()).to.be.equal(`"${fileToTest}"`);
});
test('Should replace all back slashes with forward slashes (irrespective of OS)', () => {
const fileToTest = 'c:\\users\\user\\conda\\scripts\\python.exe';
expect(fileToTest.fileToCommandArgument()).to.be.equal(fileToTest.replace(/\\/g, '/'));
});
test('Should replace all back slashes with forward slashes (irrespective of OS) and quoted when file has spaces', () => {
const fileToTest = 'c:\\users\\user namne\\conda path\\scripts\\python.exe';
expect(fileToTest.fileToCommandArgument()).to.be.equal(`"${fileToTest.replace(/\\/g, '/')}"`);
});
test('Should replace all back slashes with forward slashes (irrespective of OS) and quoted when file has spaces', () => {
const fileToTest = 'c:\\users\\user namne\\conda path\\scripts\\python.exe';
expect(fileToTest.fileToCommandArgument()).to.be.equal(`"${fileToTest.replace(/\\/g, '/')}"`);
});
test('Should leave string unchanged', () => {
expect('something {0}'.format()).to.be.equal('something {0}');
});
test('String should be formatted to contain first argument', () => {
const formatString = 'something {0}';
const expectedString = 'something one';
expect(formatString.format('one')).to.be.equal(expectedString);
});
test('String should be formatted to contain first argument even with too many args', () => {
const formatString = 'something {0}';
const expectedString = 'something one';
expect(formatString.format('one', 'two')).to.be.equal(expectedString);
});
test('String should be formatted to contain second argument', () => {
const formatString = 'something {1}';
const expectedString = 'something two';
expect(formatString.format('one', 'two')).to.be.equal(expectedString);
});
test('String should be formatted to contain second argument even with too many args', () => {
const formatString = 'something {1}';
const expectedString = 'something two';
expect(formatString.format('one', 'two', 'three')).to.be.equal(expectedString);
});
test('String should be formatted with multiple args', () => {
const formatString = 'something {1}, {0}';
const expectedString = 'something two, one';
expect(formatString.format('one', 'two', 'three')).to.be.equal(expectedString);
});
test('String should remove quotes', () => {
//tslint:disable:no-multiline-string
const quotedString = `'foo is "bar" is foo' is bar'`;
const quotedString2 = `foo is "bar" is foo' is bar'`;
const quotedString3 = `foo is "bar" is foo' is bar`;
const quotedString4 = `"foo is "bar" is foo' is bar"`;
const expectedString = `foo is "bar" is foo' is bar`;
expect(quotedString.trimQuotes()).to.be.equal(expectedString);
expect(quotedString2.trimQuotes()).to.be.equal(expectedString);
expect(quotedString3.trimQuotes()).to.be.equal(expectedString);
expect(quotedString4.trimQuotes()).to.be.equal(expectedString);
});
});