-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_arg_parsing.test.ts
41 lines (35 loc) · 989 Bytes
/
cli_arg_parsing.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
import { parseArgv } from "./cli_arg_parsing"
function parseArgvInTestMode(argv: Array<string>) {
return parseArgv(argv, { outputAndExitOnError: false })
}
test("rejects too many file arguments", () => {
expect(() => {
parseArgvInTestMode(["file1.xsc", "file2.xsc"])
}).toThrow()
})
test("rejects unknown format", () => {
expect(() => {
parseArgvInTestMode(["--format", "transcribe_version_999"])
}).toThrow()
})
test("accepts one file", () => {
expect(parseArgvInTestMode(["some file with spaces.xsc"])).toEqual({
inputSource: {
filePath: "some file with spaces.xsc",
type: "file",
},
outputFormat: "generic",
})
})
test("interprets no files as stdin", () => {
expect(parseArgvInTestMode([])).toEqual({
inputSource: { type: "stdin" },
outputFormat: "generic",
})
})
test("interprets - as stdin", () => {
expect(parseArgvInTestMode(["-"])).toEqual({
inputSource: { type: "stdin" },
outputFormat: "generic",
})
})