-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_test.ts
More file actions
60 lines (56 loc) · 1.25 KB
/
Copy pathstring_test.ts
File metadata and controls
60 lines (56 loc) · 1.25 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
import { insertVariables, removePrefix, removeSuffix } from '@rauschma/helpers/string/string.js';
import { createSuite } from '@rauschma/helpers/testing/mocha.js';
import assert from 'node:assert/strict';
createSuite(import.meta.url);
test('insertVariables()', () => {
const vars = new Map([
['first', 'Robin'],
['last', 'Doe'],
]);
assert.equal(
insertVariables(vars, '[{{first}} {{last}}]'),
'[Robin Doe]'
);
assert.equal(
insertVariables(vars, '{{first}} {{last}}'),
'Robin Doe'
);
assert.throws(
() => insertVariables(vars, '{{unknown}}'),
{
message: 'Unknown variable name "unknown" among: first,last'
}
);
assert.equal(
insertVariables(vars, String.raw`\{{escaped}} \{{double}} \{{braces}}`),
'{{escaped}} {{double}} {{braces}}'
);
});
test('removePrefix()', () => {
assert.equal(
removePrefix('_abc', '_'),
'abc'
);
assert.equal(
removePrefix('prefix', 'prefix'),
''
);
assert.equal(
removePrefix('abc', ''),
'abc'
);
});
test('removeSuffix()', () => {
assert.equal(
removeSuffix('file.txt', '.txt'),
'file'
);
assert.equal(
removeSuffix('suffix', 'suffix'),
''
);
assert.equal(
removeSuffix('my-dir', ''),
'my-dir'
);
});