1 | 'use strict'
|
2 | const TestRunner = require('test-runner')
|
3 | const a = require('assert')
|
4 | const Argv = require('../lib/argv')
|
5 | const Definitions = require('../lib/definitions')
|
6 |
|
7 | const runner = new TestRunner()
|
8 |
|
9 | runner.test('.expandOptionEqualsNotation()', function () {
|
10 | const argv = new Argv()
|
11 | argv.load([ '--one=1', '--two', '2', '--three=3', '4' ])
|
12 | argv.expandOptionEqualsNotation()
|
13 | a.deepEqual(argv, [
|
14 | '--one', '552f3a31-14cd-4ced-bd67-656a659e9efb1', '--two', '2', '--three', '552f3a31-14cd-4ced-bd67-656a659e9efb3', '4'
|
15 | ])
|
16 | })
|
17 |
|
18 | runner.test('.expandGetoptNotation()', function () {
|
19 | const argv = new Argv()
|
20 | argv.load([ '-abc' ])
|
21 | argv.expandGetoptNotation()
|
22 | a.deepEqual(argv.slice(), [
|
23 | '-a', '-b', '-c'
|
24 | ])
|
25 | })
|
26 |
|
27 | runner.test('.expandGetoptNotation() with values', function () {
|
28 | const argv = new Argv()
|
29 | argv.load([ '-abc', '1', '-a', '2', '-bc' ])
|
30 | argv.expandGetoptNotation()
|
31 | a.deepEqual(argv, [
|
32 | '-a', '-b', '-c', '1', '-a', '2', '-b', '-c'
|
33 | ])
|
34 | })
|
35 |
|
36 | runner.test('.validate()', function () {
|
37 | const definitions = new Definitions()
|
38 | definitions.load([
|
39 | { name: 'one', type: Number }
|
40 | ])
|
41 |
|
42 | a.doesNotThrow(function () {
|
43 | const argv = new Argv()
|
44 | argv.load([ '--one', '1' ])
|
45 | argv.validate(definitions)
|
46 | })
|
47 |
|
48 | a.throws(function () {
|
49 | const argv = new Argv()
|
50 | argv.load([ '--one', '--two' ])
|
51 | argv.validate(definitions)
|
52 | })
|
53 |
|
54 | a.throws(function () {
|
55 | const argv = new Argv()
|
56 | argv.load([ '--one', '2', '--two', 'two' ])
|
57 | argv.validate(definitions)
|
58 | })
|
59 |
|
60 | a.throws(function () {
|
61 | const argv = new Argv()
|
62 | argv.load([ '-a', '2' ])
|
63 | argv.validate(definitions)
|
64 | })
|
65 | })
|
66 |
|
67 | runner.test('expandOptionEqualsNotation', function () {
|
68 | const argv = new Argv()
|
69 | argv.load([ '--one=tree' ])
|
70 | argv.expandOptionEqualsNotation()
|
71 | a.deepEqual(argv, [ '--one', '552f3a31-14cd-4ced-bd67-656a659e9efbtree' ])
|
72 | })
|