1 | "use strict";
|
2 |
|
3 | var OptionsParser = require("../lib/options-parser");
|
4 |
|
5 |
|
6 | describe('Module `options-parser`', function() {
|
7 | describe('function `parse()`', function() {
|
8 | function check(should, commandLineArgs, def, expectedResult) {
|
9 | it("should " + should, function() {
|
10 | var result = OptionsParser.parse( commandLineArgs, def );
|
11 | var resultAsString = JSON.stringify( result );
|
12 | var expectedAsString = JSON.stringify( expectedResult );
|
13 | if( resultAsString != expectedAsString ) {
|
14 | fail("\nExpected " + expectedAsString + "\n"
|
15 | + " but got " + resultAsString);
|
16 | }
|
17 | });
|
18 | }
|
19 |
|
20 | check(
|
21 | "parse a command with an option",
|
22 | ["A", "B", "build", "-out", "www"], DEF1(),
|
23 | { build: { out: ["www"] } }
|
24 | );
|
25 | check(
|
26 | "parse a command without the options, but the default value must be added",
|
27 | ["A", "B", "build"], DEF1(),
|
28 | { build: { out: ["/var/www"] } }
|
29 | );
|
30 | });
|
31 | });
|
32 |
|
33 |
|
34 | function DEF1() {
|
35 | return {
|
36 | build: {
|
37 | opts: {
|
38 | out: {
|
39 | args: "/var/www"
|
40 | }
|
41 | }
|
42 | }
|
43 | };
|
44 | }
|