2019-01-01 22:46:17 -05:00
|
|
|
import { test, assertEqual } from "../../testing/mod.ts";
|
2018-12-21 13:02:52 -05:00
|
|
|
import { parse } from "../index.ts";
|
2018-12-19 13:06:31 -05:00
|
|
|
|
|
|
|
test(function numbericShortArgs() {
|
2018-12-24 10:28:01 -05:00
|
|
|
assertEqual(parse(["-n123"]), { n: 123, _: [] });
|
|
|
|
assertEqual(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] });
|
2018-12-19 13:06:31 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function short() {
|
2018-12-24 10:28:01 -05:00
|
|
|
assertEqual(parse(["-b"]), { b: true, _: [] });
|
|
|
|
assertEqual(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] });
|
|
|
|
assertEqual(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] });
|
|
|
|
assertEqual(parse(["-cats", "meow"]), {
|
|
|
|
c: true,
|
|
|
|
a: true,
|
|
|
|
t: true,
|
|
|
|
s: "meow",
|
|
|
|
_: []
|
|
|
|
});
|
|
|
|
assertEqual(parse(["-h", "localhost"]), { h: "localhost", _: [] });
|
|
|
|
assertEqual(parse(["-h", "localhost", "-p", "555"]), {
|
|
|
|
h: "localhost",
|
|
|
|
p: 555,
|
|
|
|
_: []
|
|
|
|
});
|
2018-12-19 13:06:31 -05:00
|
|
|
});
|
2018-12-24 10:28:01 -05:00
|
|
|
|
2018-12-19 13:06:31 -05:00
|
|
|
test(function mixedShortBoolAndCapture() {
|
2018-12-24 10:28:01 -05:00
|
|
|
assertEqual(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
|
|
|
|
f: true,
|
|
|
|
p: 555,
|
|
|
|
h: "localhost",
|
|
|
|
_: ["script.js"]
|
|
|
|
});
|
2018-12-19 13:06:31 -05:00
|
|
|
});
|
2018-12-24 10:28:01 -05:00
|
|
|
|
2018-12-19 13:06:31 -05:00
|
|
|
test(function shortAndLong() {
|
2018-12-24 10:28:01 -05:00
|
|
|
assertEqual(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
|
|
|
|
f: true,
|
|
|
|
p: 555,
|
|
|
|
h: "localhost",
|
|
|
|
_: ["script.js"]
|
|
|
|
});
|
2018-12-19 13:06:31 -05:00
|
|
|
});
|