summaryrefslogtreecommitdiff
path: root/flags/short_test.ts
diff options
context:
space:
mode:
authorAxetroy <troy450409405@gmail.com>2019-03-20 01:24:11 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-03-19 13:24:11 -0400
commitaae6ea51a496301011c41a874a25b77596d5c560 (patch)
treeedfcefbbbae67a1e59baa6a8d5d1fd5b6009dfec /flags/short_test.ts
parentadb19cbae366288a152dd3ab8293e5aea2edc80b (diff)
move test file out of tests dir in flags module (denoland/deno_std#293)
Original: https://github.com/denoland/deno_std/commit/e80f14489084d748bb52c4311519f5d0c7696f47
Diffstat (limited to 'flags/short_test.ts')
-rwxr-xr-xflags/short_test.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/flags/short_test.ts b/flags/short_test.ts
new file mode 100755
index 000000000..700902dd7
--- /dev/null
+++ b/flags/short_test.ts
@@ -0,0 +1,46 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import { test } from "../testing/mod.ts";
+import { assertEquals } from "../testing/asserts.ts";
+import { parse } from "./mod.ts";
+
+test(function numbericShortArgs() {
+ assertEquals(parse(["-n123"]), { n: 123, _: [] });
+ assertEquals(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] });
+});
+
+test(function short() {
+ assertEquals(parse(["-b"]), { b: true, _: [] });
+ assertEquals(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] });
+ assertEquals(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] });
+ assertEquals(parse(["-cats", "meow"]), {
+ c: true,
+ a: true,
+ t: true,
+ s: "meow",
+ _: []
+ });
+ assertEquals(parse(["-h", "localhost"]), { h: "localhost", _: [] });
+ assertEquals(parse(["-h", "localhost", "-p", "555"]), {
+ h: "localhost",
+ p: 555,
+ _: []
+ });
+});
+
+test(function mixedShortBoolAndCapture() {
+ assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
+ f: true,
+ p: 555,
+ h: "localhost",
+ _: ["script.js"]
+ });
+});
+
+test(function shortAndLong() {
+ assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
+ f: true,
+ p: 555,
+ h: "localhost",
+ _: ["script.js"]
+ });
+});