summaryrefslogtreecommitdiff
path: root/t/args.t
blob: 363baae05ad54289988ed8cadb91688420014818 (plain)
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
#!/bin/bash 
 
. t/testlib.sh
 
declare first_parser
 
set +x
 
bos-args/build-parser-code-into first_parser \
                                -scalar one scalar_var \
                                -array two array_var \
                                -assoc three assoc_var \
                                -assignment-scalar '${name}="${value}"' \
                                -assignment-array '${name}+=( "${value}" )' \
                                -assignment-assoc '${name}+=( ["${key}"]="${value}" )'
 
should-succeed "should build parser"
 
declare -a array_var
declare -A assoc_var
 
eval "function first-parser() { $first_parser }"
first-parser -two a -three x=y -random -two b -one foo -three w=z -two -not-special- -unused inputs
 
is "$scalar_var" 'foo' 'scalar should be set'
 
is "${array_var[0]}" 'a' 'array should get first value'
is "${array_var[1]}" 'b' 'array should get second value'
is "${array_var[2]}" '-not-special-' 'array should get not-special third value'
 
is "${assoc_var[x]}" 'y' 'assoc should get first value'
is "${assoc_var[w]}" 'z' 'assoc should get second value'
 
done-testing