-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.ts
59 lines (54 loc) · 1.84 KB
/
options_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
57
58
59
import { assertStrictEquals } from "@std/assert";
import * as Color from "@std/fmt/colors";
import { firstAndRest, matchType, OptionsProcessor } from "./options.ts";
let tests: Object = {};
// Test matchType
Deno.test("testMatchType", () => {
const a: string = "a",
b: number = 2,
c: boolean = true;
let x: any;
x = matchType(a, "121");
assertStrictEquals(typeof x, typeof a);
assertStrictEquals(x, "121");
x = matchType(b, 100);
assertStrictEquals(typeof x, typeof b);
assertStrictEquals(x, 100);
x = matchType(c, false);
assertStrictEquals(typeof x, typeof c);
assertStrictEquals(x, false);
x = matchType(b, "7");
assertStrictEquals(typeof x, typeof b);
assertStrictEquals(x, 7);
});
// Test firstAndRest
Deno.test("testFirstAndRest", () => {
let s = "fred zip",
parts: string[] = [];
parts = firstAndRest(s, / /);
assertStrictEquals(parts.length, 2);
assertStrictEquals(parts[0], "fred");
assertStrictEquals(parts[1], "zip");
});
// Test Options object
Deno.test("testOptionsObject", () => {
const argv = ["-help", "-url=http://localhost:3030", "-retry", "7"];
let op = new OptionsProcessor();
op.booleanVar("help", false, "display help");
op.stringVar("url", "", "set URL");
op.numberVar("retry", 1, "set retries");
op.parse(argv);
//console.log("DEBUG op -> ", op)
assertStrictEquals(op.options.help, true);
assertStrictEquals(op.options.url, "http://localhost:3030");
assertStrictEquals(op.options.retry, 7);
op = new OptionsProcessor();
op.booleanVar("help", false, "display help");
op.stringVar("url", "", "set URL");
op.numberVar("retry", 1, "set retries");
op.parse(argv.slice(1, argv.length));
//console.log("DEBUG op -> ", op)
assertStrictEquals(op.options.help, false);
assertStrictEquals(op.options.url, "http://localhost:3030");
assertStrictEquals(op.options.retry, 7);
});