|
| 1 | +# confutils |
| 2 | +# Copyright (c) 2018-2025 Status Research & Development GmbH |
| 3 | +# Licensed under either of |
| 4 | +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) |
| 5 | +# * MIT license ([LICENSE-MIT](LICENSE-MIT)) |
| 6 | +# at your option. |
| 7 | +# This file may not be copied, modified, or distributed except according to |
| 8 | +# those terms. |
| 9 | + |
| 10 | +import unittest2, ../confutils, ./help/test_argument |
| 11 | + |
| 12 | +suite "test argument": |
| 13 | + test "no command": |
| 14 | + let conf = TestConf.load(cmdLine = @[]) |
| 15 | + check: |
| 16 | + conf.cmd == Lvl1Cmd.noCommand |
| 17 | + |
| 18 | + test "pass arg first to argAfterOpt": |
| 19 | + let conf = TestConf.load(cmdLine = @[ |
| 20 | + "argAfterOpt", |
| 21 | + "foo", |
| 22 | + "--arg-after-opt-opt1=bar" |
| 23 | + ]) |
| 24 | + check: |
| 25 | + conf.cmd == Lvl1Cmd.argAfterOpt |
| 26 | + conf.arg1 == "foo" |
| 27 | + conf.opt1 == "bar" |
| 28 | + |
| 29 | + test "pass arg last to argAfterOpt": |
| 30 | + let conf = TestConf.load(cmdLine = @[ |
| 31 | + "argAfterOpt", |
| 32 | + "--arg-after-opt-opt1=bar", |
| 33 | + "foo" |
| 34 | + ]) |
| 35 | + check: |
| 36 | + conf.cmd == Lvl1Cmd.argAfterOpt |
| 37 | + conf.arg1 == "foo" |
| 38 | + conf.opt1 == "bar" |
| 39 | + |
| 40 | + test "pass arg first to argBeforeOpt": |
| 41 | + let conf = TestConf.load(cmdLine = @[ |
| 42 | + "argBeforeOpt", |
| 43 | + "foo", |
| 44 | + "--arg-before-opt-opt2=bar" |
| 45 | + ]) |
| 46 | + check: |
| 47 | + conf.cmd == Lvl1Cmd.argBeforeOpt |
| 48 | + conf.arg2 == "foo" |
| 49 | + conf.opt2 == "bar" |
| 50 | + |
| 51 | + test "pass arg last to argBeforeOpt": |
| 52 | + let conf = TestConf.load(cmdLine = @[ |
| 53 | + "argBeforeOpt", |
| 54 | + "--arg-before-opt-opt2=bar", |
| 55 | + "foo" |
| 56 | + ]) |
| 57 | + check: |
| 58 | + conf.cmd == Lvl1Cmd.argBeforeOpt |
| 59 | + conf.arg2 == "foo" |
| 60 | + conf.opt2 == "bar" |
| 61 | + |
| 62 | + test "pass arg first to argAroundOpt": |
| 63 | + let conf = TestConf.load(cmdLine = @[ |
| 64 | + "argAroundOpt", |
| 65 | + "foo", |
| 66 | + "bar", |
| 67 | + "--arg-around-opt-opt3=baz" |
| 68 | + ]) |
| 69 | + check: |
| 70 | + conf.cmd == Lvl1Cmd.argAroundOpt |
| 71 | + conf.arg4 == "foo" |
| 72 | + conf.arg5 == "bar" |
| 73 | + conf.opt3 == "baz" |
| 74 | + |
| 75 | + test "pass arg last to argAroundOpt": |
| 76 | + let conf = TestConf.load(cmdLine = @[ |
| 77 | + "argAroundOpt", |
| 78 | + "--arg-around-opt-opt3=baz", |
| 79 | + "foo", |
| 80 | + "bar" |
| 81 | + ]) |
| 82 | + check: |
| 83 | + conf.cmd == Lvl1Cmd.argAroundOpt |
| 84 | + conf.arg4 == "foo" |
| 85 | + conf.arg5 == "bar" |
| 86 | + conf.opt3 == "baz" |
| 87 | + |
| 88 | + test "pass arg mix to argAroundOpt": |
| 89 | + let conf = TestConf.load(cmdLine = @[ |
| 90 | + "argAroundOpt", |
| 91 | + "foo", |
| 92 | + "--arg-around-opt-opt3=baz", |
| 93 | + "bar" |
| 94 | + ]) |
| 95 | + check: |
| 96 | + conf.cmd == Lvl1Cmd.argAroundOpt |
| 97 | + conf.arg4 == "foo" |
| 98 | + conf.arg5 == "bar" |
| 99 | + conf.opt3 == "baz" |
0 commit comments