-
-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathoptions.js
More file actions
54 lines (44 loc) · 1.66 KB
/
options.js
File metadata and controls
54 lines (44 loc) · 1.66 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
import assert from "assert";
import * as optionsUtil from "../../util/options.js";
const config = {
"enable": {
"type": "S",
"mutuallyExclusive": "disable"
},
"disable": {
"type": "S",
"mutuallyExclusive": "enable"
},
"other": {
"type": "S",
"default": ["x"]
}
};
// Present in both should concat
let merged = optionsUtil.merge(config, { enable: ["a"] }, { enable: ["b"] });
assert.deepStrictEqual(merged.enable, ["a", "b"]);
merged = optionsUtil.merge(config, { enable: ["a"] }, { enable: ["a", "b"] });
assert.deepStrictEqual(merged.enable, ["a", "b"]);
// Mutually exclusive should exclude
merged = optionsUtil.merge(config, { enable: ["a", "b"] }, { disable: ["a", "c"] });
assert.deepStrictEqual(merged.enable, ["a", "b"]);
assert.deepStrictEqual(merged.disable, ["c"]);
merged = optionsUtil.merge(config, { disable: ["a", "b"] }, { enable: ["a", "c"] });
assert.deepStrictEqual(merged.enable, ["c"]);
assert.deepStrictEqual(merged.disable, ["a", "b"]);
// Populating defaults should work after the fact
optionsUtil.addDefaults(config, merged = {});
assert.deepStrictEqual(merged.other, ["x"]);
optionsUtil.addDefaults(config, merged = { other: ["y"] });
assert.deepStrictEqual(merged.other, ["y"]);
// Complete usage test
let result = optionsUtil.parse([
"--enable", "a",
"--disable", "b",
], config, false);
merged = optionsUtil.merge(config, result.options, { enable: ["b", "c"] });
merged = optionsUtil.merge(config, merged, { disable: ["a", "d"] });
optionsUtil.addDefaults(config, merged);
assert.deepStrictEqual(merged.enable, ["a", "c"]);
assert.deepStrictEqual(merged.disable, ["b", "d"]);
assert.deepStrictEqual(merged.other, ["x"]);