values.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var nomnom = require("../nomnom");
  2. var opts = {
  3. debug: {
  4. flag: true
  5. },
  6. verbose: {
  7. flag: true,
  8. default: true
  9. },
  10. list1: {
  11. list: true
  12. },
  13. list2: {
  14. list: true
  15. },
  16. list3: {
  17. position: 1,
  18. list: true
  19. },
  20. num1: {
  21. type: "string"
  22. },
  23. def1: {
  24. default: "val1"
  25. },
  26. def2: {
  27. default: "val1"
  28. }
  29. }
  30. var parser = nomnom().options(opts);
  31. exports.testFlag = function(test) {
  32. var options = parser.parse(["--debug", "pos0", "--no-verbose"]);
  33. test.strictEqual(options.debug, true);
  34. test.strictEqual(options.verbose, false);
  35. test.equal(options[0], "pos0");
  36. test.equal(options._[0], "pos0");
  37. test.done();
  38. }
  39. exports.testList = function(test) {
  40. var options = parser.parse(["pos0", "pos1", "--list1=val0", "--list2", "val1",
  41. "--list2", "val2", "pos2"]);
  42. test.deepEqual(options.list1, ["val0"]);
  43. test.deepEqual(options.list2, ["val1", "val2"]);
  44. test.deepEqual(options.list3, ["pos1", "pos2"]);
  45. test.done();
  46. }
  47. exports.testDefault = function(test) {
  48. var options = parser.parse(["--def2", "val2", "--def3", "val3"]);
  49. test.strictEqual(options.def1, "val1");
  50. test.strictEqual(options.def2, "val2");
  51. test.strictEqual(options.def3, "val3");
  52. test.done();
  53. }
  54. exports.testTypes = function(test) {
  55. var options = parser.parseArgs(["", "-x", "3.14", "-w", "true", "-q", "120",
  56. "--num1", "4"]);
  57. test.strictEqual(options[0], "");
  58. test.strictEqual(options.x, 3.14);
  59. test.strictEqual(options.w, true);
  60. test.strictEqual(options.q, 120);
  61. test.strictEqual(options.num1, "4");
  62. test.done();
  63. }