push
github
194 of 210 branches covered (92.38%)
Branch coverage included in aggregate %.
675 of 695 relevant lines covered (97.12%)
62.24 hits per line
1 |
export default class Params { |
|
2 |
constructor(params = '', context) {
|
|
3 |
// params = ..<required> ..[optional]
|
312✔ |
4 |
// <foo> - required
|
312✔ |
5 |
// [foo] - optional
|
312✔ |
6 |
let left = params.trim(); |
312✔ |
7 |
let m; |
312✔ |
8 |
|
312✔ |
9 |
this.args = [];
|
312✔ |
10 |
|
312✔ |
11 |
while (m = left.match(/^<([^>]+)>\s*/)) { |
|
12 |
left = left.slice(m[0].length);
|
32✔ |
13 |
this.args.push({ name: m[1], required: true }); |
32✔ |
14 |
} |
32✔ |
15 |
|
312✔ |
16 |
this.minCount = this.args.length; |
312✔ |
17 |
|
312✔ |
18 |
while (m = left.match(/^\[([^\]]+)\]\s*/)) { |
|
19 |
left = left.slice(m[0].length);
|
40✔ |
20 |
this.args.push({ name: m[1], required: false }); |
40✔ |
21 |
} |
40✔ |
22 |
|
312✔ |
23 |
this.maxCount = this.args.length; |
312✔ |
24 |
|
312✔ |
25 |
if (left) {
|
|
26 |
throw new Error(`Bad parameters description "${params.trim()}" in ${context}`); |
× |
27 |
} |
× |
28 |
} |
312✔ |
29 |
}; |
1✔ |