summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorParashurama <Rhagdamaziel@ymail.com>2017-06-06 13:47:34 +0200
committerParashurama <Rhagdamaziel@ymail.com>2017-06-06 13:50:26 +0200
commit27e2a343403197af08d20207ac884cf134d4892e (patch)
tree7861a1b048d20882184cd759cdbb1452d8c562ff /tests
parentc59bc0cc183ccaed25e8e4a3cc286f2bb351405b (diff)
downloadNim-27e2a343403197af08d20207ac884cf134d4892e.tar.gz
fixes parseopt/parseopt2 custom cmdline args.
Diffstat (limited to 'tests')
-rw-r--r--tests/misc/tparseopt.nim57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/misc/tparseopt.nim b/tests/misc/tparseopt.nim
new file mode 100644
index 000000000..1f8375dfd
--- /dev/null
+++ b/tests/misc/tparseopt.nim
@@ -0,0 +1,57 @@
+discard """
+  file: "tparseopt.nim"
+  output: '''
+parseopt
+first round
+kind: cmdLongOption	key:val  --  left:
+second round
+kind: cmdLongOption	key:val  --  left:
+kind: cmdLongOption	key:val  --  debug:3
+kind: cmdShortOption	key:val  --  l:4
+kind: cmdShortOption	key:val  --  r:2
+parseopt2
+first round
+kind: cmdLongOption	key:val  --  left:
+second round
+kind: cmdLongOption	key:val  --  left:
+kind: cmdLongOption	key:val  --  debug:3
+kind: cmdShortOption	key:val  --  l:4
+kind: cmdShortOption	key:val  --  r:2'''
+"""
+from parseopt import nil
+from parseopt2 import nil
+
+
+block:
+    echo "parseopt"
+    for kind, key, val in parseopt.getopt():
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val
+
+    # pass custom cmdline arguments
+    echo "first round"
+    var argv = "--left --debug:3 -l=4 -r:2"
+    var p = parseopt.initOptParser(argv)
+    for kind, key, val in parseopt.getopt(p):
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val
+      break
+    # reset getopt iterator and check arguments are returned correctly.
+    echo "second round"
+    for kind, key, val in parseopt.getopt(p):
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val
+
+block:
+    echo "parseopt2"
+    for kind, key, val in parseopt2.getopt():
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val
+
+    # pass custom cmdline arguments
+    echo "first round"
+    var argv: seq[string] = @["--left", "--debug:3", "-l=4", "-r:2"]
+    var p = parseopt2.initOptParser(argv)
+    for kind, key, val in parseopt2.getopt(p):
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val
+      break
+    # reset getopt iterator and check arguments are returned correctly.
+    echo "second round"
+    for kind, key, val in parseopt2.getopt(p):
+      echo "kind: ", kind, "\tkey:val  --  ", key, ":", val