aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nomnom/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/nomnom/test')
-rw-r--r--node_modules/nomnom/test/callback.js33
-rw-r--r--node_modules/nomnom/test/commands.js120
-rw-r--r--node_modules/nomnom/test/expected.js60
-rw-r--r--node_modules/nomnom/test/matching.js70
-rw-r--r--node_modules/nomnom/test/option.js44
-rw-r--r--node_modules/nomnom/test/transform.js65
-rw-r--r--node_modules/nomnom/test/usage.js121
-rw-r--r--node_modules/nomnom/test/values.js75
8 files changed, 588 insertions, 0 deletions
diff --git a/node_modules/nomnom/test/callback.js b/node_modules/nomnom/test/callback.js
new file mode 100644
index 000000000..3d512dbed
--- /dev/null
+++ b/node_modules/nomnom/test/callback.js
@@ -0,0 +1,33 @@
+var nomnom = require("../nomnom");
+
+exports.testVersion = function(test) {
+ test.expect(1);
+
+ nomnom().options({
+ date: {
+ callback: function(date) {
+ test.equal(date, "2010-02-03", "date should match value")
+ }
+ }
+ }).parse(["--date=2010-02-03"]);
+
+ test.done();
+}
+
+exports.testReturnString = function(test) {
+ test.expect(1);
+
+ nomnom().options({
+ version: {
+ flag: true,
+ callback: function() {
+ return "v0.3";
+ }
+ }
+ })
+ .printer(function(string) {
+ test.equal(0, string.indexOf("v0.3"))
+ test.done();
+ })
+ .parse(["--version"]);
+} \ No newline at end of file
diff --git a/node_modules/nomnom/test/commands.js b/node_modules/nomnom/test/commands.js
new file mode 100644
index 000000000..1fbb60f6a
--- /dev/null
+++ b/node_modules/nomnom/test/commands.js
@@ -0,0 +1,120 @@
+var nomnom = require("../nomnom");
+
+function strip(str) {
+ return str.replace(/\s+/g, '');
+}
+
+exports.testCallback = function(test) {
+ test.expect(1);
+
+ var parser = nomnom();
+ parser.command('run').callback(function(options) {
+ test.equal(options.v, 3);
+ });
+ parser.command('other').callback(function() {
+ test.ok(false, "callback for other command shouldn't be called");
+ });
+
+ parser.parse(["run","-v", "3"]);
+ test.done();
+}
+
+exports.testMissingCommand = function(test) {
+ test.expect(1);
+
+ var parser = nomnom().scriptName("test");
+
+ parser.command('run');
+
+ parser.printer(function(string) {
+ test.equal(string, "test: no such command 'other'");
+ test.done();
+ });
+
+ parser.parse(["other"]);
+}
+
+exports.testNoCommand = function(test) {
+ test.expect(2);
+
+ var parser = nomnom();
+
+ parser.nocommand()
+ .options({
+ version: {
+ flag: true
+ }
+ })
+ .callback(function(options) {
+ test.strictEqual(options.version, true);
+ })
+ .usage("fallback usage");
+
+ parser.command('run');
+
+ var options = parser.parse(["--version"]);
+
+ test.strictEqual(options.version, true);
+ test.done();
+}
+
+function createParser() {
+ var parser = nomnom().scriptName("test")
+ .options({
+ debug: {
+ flag: true
+ }
+ });
+
+ parser.command('run')
+ .options({
+ file: {
+ help: 'file to run'
+ }
+ })
+ .help("run all");
+
+ parser.command('test').usage("test usage");
+
+ parser.nocommand()
+ .options({
+ verbose: {
+ flag: true
+ }
+ })
+ .help("nocommand");
+
+ return parser;
+}
+
+exports.testUsage = function(test) {
+ test.expect(4);
+
+ var parser = createParser();
+ parser.printer(function(string) {
+ test.equal(strip(string), "testusage");
+ });
+ parser.parse(["test", "-h"]);
+
+ parser = createParser().nocolors();
+ parser.printer(function(string) {
+ test.equal(strip(string), "Usage:testrun[options]Options:--debug--filefiletorunrunall");
+ });
+ parser.parse(["run", "-h"]);
+
+ parser = createParser().nocolors();
+ parser.printer(function(string) {
+ test.equal(strip(string), "Usage:test[command][options]commandoneof:run,testOptions:--debug--verbosenocommand");
+ });
+ parser.parse(["-h"]);
+
+ parser = createParser().nocolors();
+ parser.nocommand()
+ .usage("fallback");
+ parser.printer(function(string) {
+ test.equal(strip(string), "fallback");
+ });
+ parser.parse(["-h"]);
+
+ test.done();
+}
diff --git a/node_modules/nomnom/test/expected.js b/node_modules/nomnom/test/expected.js
new file mode 100644
index 000000000..f52bd57de
--- /dev/null
+++ b/node_modules/nomnom/test/expected.js
@@ -0,0 +1,60 @@
+var nomnom = require("../nomnom");
+
+var opts = {
+ file: {
+ position: 0,
+ required: true
+ }
+}
+
+var parser = nomnom().options(opts);
+
+exports.testFlag = function(test) {
+ test.expect(1);
+
+ nomnom().options({
+ file: {
+ position: 0,
+ }
+ })
+ .printer(function(string) {
+ test.equal(0, string.indexOf("'--key1' expects a value"))
+ test.done();
+ })
+ .parse(["--key1"]);
+}
+
+exports.testRequired = function(test) {
+ test.expect(1);
+
+ nomnom().options({
+ file: {
+ required: true
+ }
+ })
+ .printer(function(string) {
+ test.equal(0, string.trim().indexOf("file argument is required"))
+ test.done();
+ })
+ .nocolors()
+ .parse([]);
+}
+
+exports.testChoices = function(test) {
+ test.expect(2);
+
+ var parser = nomnom().options({
+ color: {
+ choices: ['green', 'blue']
+ }
+ })
+ .printer(function(string) {
+ test.equal(0, string.indexOf("color must be one of: green, blue"))
+ });
+
+ parser.parse(['--color', 'red']);
+
+ var options = parser.parse(['--color', 'green']);
+ test.equal(options.color, 'green');
+ test.done();
+}
diff --git a/node_modules/nomnom/test/matching.js b/node_modules/nomnom/test/matching.js
new file mode 100644
index 000000000..8d347eb0f
--- /dev/null
+++ b/node_modules/nomnom/test/matching.js
@@ -0,0 +1,70 @@
+var nomnom = require("../nomnom");
+
+var opts = {
+ pos1: {
+ position: 0
+ },
+ pos2: {
+ position: 1
+ },
+ flag1: {
+ flag: true
+ },
+ debug: {
+ abbr: 'd'
+ },
+ numLines: {
+ abbr: 'n',
+ full: 'num-lines'
+ },
+ version: {
+ string: '-v, --version'
+ },
+ config: {
+ string: '-c FILE, --config=FILE'
+ },
+ skey : {
+ string: '-k val'
+ },
+ skey2: {
+ string: '-k2 val2, --key2 val2'
+ },
+ skey3: {
+ string: '--key3=val'
+ },
+ skey4: {
+ string: '--key4=val, -y val'
+ }
+}
+
+var parser = nomnom().options(opts);
+
+exports.testPositional = function(test) {
+ var options = parser.parse(["--flag1", "val1", "--config", "file", "val2"]);
+
+ test.equal(options.pos1, "val1");
+ test.equal(options.pos2, "val2");
+ test.deepEqual(options._, ["val1", "val2"])
+ test.done();
+}
+
+exports.testAbbr = function(test) {
+ var options = parser.parse(["-d", "yes", "--num-lines", "3"]);
+
+ test.equal(options.debug, "yes")
+ test.equal(options.numLines, 3)
+ test.done();
+}
+
+exports.testString = function(test) {
+ var options = parser.parse(["-k", "val", "--config=test.js",
+ "--key2", "val2", "--key3", "val3", "--key4=val4", "-v", "v0.3"]);
+
+ test.equal(options.version, "v0.3")
+ test.equal(options.config, "test.js")
+ test.equal(options.skey, "val")
+ test.equal(options.skey2, "val2")
+ test.equal(options.skey3, "val3")
+ test.equal(options.skey4, "val4")
+ test.done();
+}
diff --git a/node_modules/nomnom/test/option.js b/node_modules/nomnom/test/option.js
new file mode 100644
index 000000000..e3934d75e
--- /dev/null
+++ b/node_modules/nomnom/test/option.js
@@ -0,0 +1,44 @@
+var nomnom = require("../nomnom");
+
+var parser = nomnom()
+ .option('debug', {
+ abbr: 'x',
+ flag: true,
+ help: 'Print debugging info'
+ })
+ .option('config', {
+ abbr: 'c',
+ default: 'config.json',
+ help: 'JSON file with tests to run'
+ })
+ .option('version', {
+ flag: true,
+ help: 'print version and exit',
+ callback: function() {
+ return "version 1.2.4";
+ }
+ });
+
+
+exports.testOption = function(test) {
+ var opts = parser.parse(["-x", "--no-verbose"]);
+
+ test.strictEqual(opts.debug, true);
+ test.equal(opts.config, "config.json");
+ test.done();
+}
+
+
+exports.testCommandOption = function(test) {
+ var parser = nomnom()
+ parser.command('test')
+ .option('fruit', {
+ abbr: 'f',
+ flag: true
+ })
+
+ var opts = parser.parse(["test", "-f"]);
+
+ test.strictEqual(opts.fruit, true);
+ test.done();
+}
diff --git a/node_modules/nomnom/test/transform.js b/node_modules/nomnom/test/transform.js
new file mode 100644
index 000000000..666a6a233
--- /dev/null
+++ b/node_modules/nomnom/test/transform.js
@@ -0,0 +1,65 @@
+var nomnom = require("../nomnom");
+
+var parser = nomnom()
+ .option("addr", {
+ abbr: "a",
+ help: "host:port address",
+ transform: function(value) {
+ var parts = value.split(":");
+ return {host: parts[0], port: Number(parts[1])};
+ }
+ })
+ .option("string", {
+ abbr: "s",
+ help: "always a string",
+ transform: function(value) {
+ return value.toString();
+ }
+ });
+
+
+exports.testTransformComplexValue = function(test) {
+ var opts = parser.parse(["-a", "localhost:1234"]);
+
+ test.strictEqual(opts.addr.host, "localhost");
+ test.strictEqual(opts.addr.port, 1234);
+ test.done();
+};
+
+
+exports.testTransformString = function(test) {
+ var opts = parser.parse(["-s", "3"]);
+
+ test.strictEqual(opts.string, "3");
+ test.done();
+};
+
+
+exports.testTransformCommand = function(test) {
+ test.expect(1);
+
+ var parser = nomnom().scriptName("test")
+ .options({
+ addr: {
+ transform: function(value) {
+ var parts = value.split(":");
+ return {host: parts[0], port: Number(parts[1])};
+ }
+ }
+ });
+
+ parser.command("run")
+ .options({
+ string: {
+ transform: function(value) {
+ return value.toString();
+ }
+ }
+ })
+ .callback(function(options) {
+ test.strictEqual(options.string, "true");
+ });
+
+ parser.parse(["run", "--string=true"]);
+ test.done();
+};
diff --git a/node_modules/nomnom/test/usage.js b/node_modules/nomnom/test/usage.js
new file mode 100644
index 000000000..9a0817935
--- /dev/null
+++ b/node_modules/nomnom/test/usage.js
@@ -0,0 +1,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"]);
+}
diff --git a/node_modules/nomnom/test/values.js b/node_modules/nomnom/test/values.js
new file mode 100644
index 000000000..797807e5e
--- /dev/null
+++ b/node_modules/nomnom/test/values.js
@@ -0,0 +1,75 @@
+var nomnom = require("../nomnom");
+
+var opts = {
+ debug: {
+ flag: true
+ },
+ verbose: {
+ flag: true,
+ default: true
+ },
+ list1: {
+ list: true
+ },
+ list2: {
+ list: true
+ },
+ list3: {
+ position: 1,
+ list: true
+ },
+ num1: {
+ type: "string"
+ },
+ def1: {
+ default: "val1"
+ },
+ def2: {
+ default: "val1"
+ }
+}
+
+var parser = nomnom().options(opts);
+
+exports.testFlag = function(test) {
+ var options = parser.parse(["--debug", "pos0", "--no-verbose"]);
+
+ test.strictEqual(options.debug, true);
+ test.strictEqual(options.verbose, false);
+ test.equal(options[0], "pos0");
+ test.equal(options._[0], "pos0");
+ test.done();
+}
+
+exports.testList = function(test) {
+ var options = parser.parse(["pos0", "pos1", "--list1=val0", "--list2", "val1",
+ "--list2", "val2", "pos2"]);
+
+ test.deepEqual(options.list1, ["val0"]);
+ test.deepEqual(options.list2, ["val1", "val2"]);
+ test.deepEqual(options.list3, ["pos1", "pos2"]);
+ test.done();
+}
+
+exports.testDefault = function(test) {
+ var options = parser.parse(["--def2", "val2", "--def3", "val3"]);
+
+ test.strictEqual(options.def1, "val1");
+ test.strictEqual(options.def2, "val2");
+ test.strictEqual(options.def3, "val3");
+ test.done();
+}
+
+exports.testTypes = function(test) {
+ var options = parser.parseArgs(["", "-x", "3.14", "-w", "true", "-q", "120",
+ "--num1", "4"]);
+
+ test.strictEqual(options[0], "");
+ test.strictEqual(options.x, 3.14);
+ test.strictEqual(options.w, true);
+ test.strictEqual(options.q, 120);
+ test.strictEqual(options.num1, "4");
+ test.done();
+}
+
+