/
yargs-test.ts
56 lines (49 loc) · 1.29 KB
/
yargs-test.ts
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
/* global Deno */
import {
assertEquals
} from 'https://deno.land/std/testing/asserts.ts'
import parser from '../../deno.ts'
// Parser:
Deno.test('parse string', () => {
const parsed = parser('--foo --bar 99')
assertEquals(parsed.foo, true)
assertEquals(parsed.bar, 99)
})
Deno.test('parse array', () => {
const parsed = parser(['--foo', '--bar', '99'])
assertEquals(parsed.foo, true)
assertEquals(parsed.bar, 99)
})
Deno.test('aliases', () => {
const parsed = parser(['--bar', '99'], {
alias: {
bar: ['foo'],
foo: ['f']
}
})
assertEquals(parsed.bar, 99)
assertEquals(parsed.foo, 99)
assertEquals(parsed.f, 99)
})
const jsonPath = './test/fixtures/config.json'
Deno.test('should load options and values from default config if specified', () => {
var argv = parser(['--foo', 'bar'], {
alias: {
z: 'zoom'
},
default: {
settings: jsonPath
},
config: 'settings'
})
assertEquals(argv.herp, 'derp')
assertEquals(argv.zoom, 55)
assertEquals(argv.zoom, 55)
})
// String utilities:
Deno.test('convert hyphenated string to camelcase', () => {
assertEquals(parser.camelCase('hello-world'), 'helloWorld')
})
Deno.test('convert camelcase string to hyphenated', () => {
assertEquals(parser.decamelize('helloWorld'), 'hello-world')
})