-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistDir.spec.ts
54 lines (43 loc) · 1.86 KB
/
listDir.spec.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
import { apply, either } from 'fp-ts'
import { pipe } from 'fp-ts/function'
import * as D from 'io-ts/Decoder'
import { Command, Opts } from '../../src'
import { decoderToDecode } from '../../src/utils'
const Color = { decoder: D.union(D.literal('always'), D.literal('auto'), D.literal('never')) }
type Color = D.TypeOf<typeof Color.decoder>
const color = pipe(
Opts.option(decoderToDecode(Color.decoder))({
long: 'color',
metavar: 'when',
help: "Colorize the output: 'always', 'auto', or 'never'",
}),
Opts.withDefault<Color>(() => 'always'),
)
const all = pipe(
Opts.flag({ long: 'all', short: 'a', help: 'Do not ignore hidden files.' }),
Opts.orFalse,
)
const directory = pipe(Opts.argumentS(either.right)('directory'), Opts.orEmpty)
const listDir = Command({ name: 'ls', header: 'List information about files.' })(
apply.sequenceT(Opts.opts)(color, all, directory),
)
describe('listDir', () => {
it('should parse command', () => {
expect(Command.parse([])(listDir)).toStrictEqual(either.right(['always', false, []]))
expect(Command.parse(['--color', 'auto'])(listDir)).toStrictEqual(
either.right(['auto', false, []]),
)
expect(Command.parse(['--color', 'never'])(listDir)).toStrictEqual(
either.right(['never', false, []]),
)
expect(Command.parse(['--all'])(listDir)).toStrictEqual(either.right(['always', true, []]))
expect(Command.parse(['-a'])(listDir)).toStrictEqual(either.right(['always', true, []]))
expect(Command.parse(['dir'])(listDir)).toStrictEqual(either.right(['always', false, ['dir']]))
expect(Command.parse(['dir1', 'dir2'])(listDir)).toStrictEqual(
either.right(['always', false, ['dir1', 'dir2']]),
)
expect(
Command.parse(['dir1', '--color', 'auto', 'dir2', '--all', 'dir3'])(listDir),
).toStrictEqual(either.right(['auto', true, ['dir1', 'dir2', 'dir3']]))
})
})