-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
52 lines (44 loc) · 1.42 KB
/
index.spec.ts
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
import { assert } from 'chai';
import 'mocha';
import { expandUser, expandVars } from './index';
import { homedir } from 'os';
describe('expanduser', () => {
const fakeHome = '/home/example';
it('unbound', () => {
assert.equal(expandUser('~'), homedir());
});
it('$HOME', () => {
const expand = expandUser.bind({ HOME: fakeHome });
assert.equal(expand('~'), fakeHome);
});
it('$USERPROFILE', () => {
const expand = expandUser.bind({ USERPROFILE: fakeHome });
assert.equal(expand('~'), fakeHome);
});
});
describe('expandvars', () => {
it('constants', () => {
assert.equal(expandVars('FOO'), 'FOO');
assert.equal(expandVars('$'), '$');
assert.equal(expandVars('BAR$'), 'BAR$');
});
it('empty', () => {
assert.equal(expandVars(''), '');
assert.equal(expandVars('$FOO'), '$FOO');
});
it('simple', () => {
const expand = expandVars.bind({ FOO: 'bar' });
assert.equal(expand('$FOO'), 'bar');
assert.equal(expand('${FOO}'), 'bar');
});
it('combo', () => {
const expand = expandVars.bind({ FOO: 'bar', BIZ: 'buz' });
assert.equal(expand('${FOO}:$BIZ'), 'bar:buz');
assert.equal(expand('$FOO$BIZ'), 'barbuz');
assert.equal(expand('${FOO}$BIZ'), 'barbuz');
assert.equal(expand('$FOO${BIZ}'), 'barbuz');
assert.equal(expand('$FOO-$BIZ'), 'bar-buz');
assert.equal(expand('boo$BIZ'), 'boobuz');
assert.equal(expand('boo${BIZ}'), 'boobuz');
});
});