aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nomnom/test/usage.js
blob: 9a08179358d04a21ceff511d0ac1620753cc258d (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var nomnom = require("../nomnom");

function strip(str) {
  return str.replace(/\s+/g, '');
};

var opts = {
   apple: {
      abbr: 'a',
      help: 'how many apples'
   },

   banana: {
      full: "b-nana"
   },

   carrot: {
      string: '-c NUM, --carrots=NUM'
   },

   dill: {
      metavar: 'PICKLE'
   },

   egg: {
      position: 0,
      help: 'robin'
   }
}

var parser = nomnom().options(opts).help("all the best foods").scriptName("test").nocolors();

var expected = "Usage:test[egg][options]eggrobinOptions:-a,--applehowmanyapples--b-nana-cNUM,--carrots=NUM--dillPICKLEallthebestfoods"

exports.testH = function(test) {
   test.expect(1);

   parser.printer(function(string) {
      test.equal(strip(string), expected)
      test.done();
   })
   .nocolors()
   .parse(["-h"]);
}

exports.testHelp = function(test) {
   test.expect(1);

   parser.printer(function(string) {
      test.equal(strip(string), expected)
      test.done();
   })
   .nocolors()
   .parse(["--help"]);
}

exports.testScriptName = function(test) {
   test.expect(1);

   nomnom()
     .script("test")
     .printer(function(string) {
        test.equal(strip(string),"Usage:test")
        test.done();
     })
     .nocolors()
     .parse(["-h"]);
}

exports.testUsage = function(test) {
   test.expect(1);

   parser
      .usage("test usage")
      .printer(function(string) {
         test.equal(string, "test usage")
         test.done();
      })
      .nocolors()
      .parse(["--help"]);
}

exports.testHidden = function(test) {
   test.expect(1);

   nomnom().options({
      file: {
         hidden: true
      }
   })
   .scriptName("test")
   .printer(function(string) {
      test.equal(strip("Usage:test[options]Options:"), strip(string))
      test.done();
   })
   .nocolors()
   .parse(["-h"]);
}

exports.testRequiredOptional = function(test) {
   test.expect(1);

   nomnom().options({
      foo: {
         position: 0,
         required: true,
         help: 'The foo'
      },
      bar: {
         position: 1,
         help: 'The bar'
      }
   })
   .scriptName("test")
   .printer(function(string) {
      test.equal(strip("Usage:test<foo>[bar]fooThefoobarThebar"), strip(string))
      test.done();
   })
   .nocolors()
   .parse(["-h"]);
}